Skip to content

After enum overhaul in TS 5.0, should we allow type assertion: number as Enum when number is not a valid enum?Β #54699

@gpskalra

Description

@gpskalra

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

This is a change in behavior since TS 5.0 as listed here https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#enum-overhaul

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

enum Color {
  Red = 1,
  Yellow = 2
}

let color1: Color = 3; // fail
let color2: Color = 3 as Color; // should this be allowed?

πŸ™ Actual behavior

This line does not throw an error

let color2: Color = 3 as Color; // should this be allowed?

πŸ™‚ Expected behavior

The aim of the enum overhaul was to catch errors where illegal values are assigned to the enum. With "as" being still present, it is still possible to assign illegal values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions