Skip to content

Inconsistent behavior between assignment and "as" with object literals after enums unificationΒ #51466

@jakebailey

Description

@jakebailey

Bug Report

πŸ”Ž Search Terms

Conversion may be a mistake enum unification object literal as

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions 4.9 and 5.0

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

enum Foo {
    None = +0,
    A = 1,
    B = 2,
    C = 4,
}

interface UsesFoo {
    foo: Foo;
}


const x = { 
    foo: 7
} as UsesFoo;

const y: UsesFoo = { 
    foo: 7
};

πŸ™ Actual behavior

There's an error on the first assignment and no error on the second assignment.

πŸ™‚ Expected behavior

Probably, no errors on either? Or something consistent?

This is a method suggested by https://devblogs.microsoft.com/typescript/announcing-typescript-4-3/#union-enums-cannot-be-compared-to-arbitrary-numbers (and I minimized this from OWA).

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions