Skip to content

Commit 4220f58

Browse files
committed
Any numeric literal type is assignable to a computed numeric enum type
1 parent 5f989cd commit 4220f58

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18759,12 +18759,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1875918759
if (relation === assignableRelation || relation === comparableRelation) {
1876018760
if (s & TypeFlags.Any) return true;
1876118761
// Type number is assignable to any computed numeric enum type or any numeric enum literal type, and
18762-
// a numeric literal type is assignable to any numeric enum literal type with a matching value. These
18763-
// rules exist such that enums can be used for bit-flag purposes.
18762+
// a numeric literal type is assignable any computed numeric enum type or any numeric enum literal type
18763+
// with a matching value. These rules exist such that enums can be used for bit-flag purposes.
1876418764
if (s & TypeFlags.Number && (t & TypeFlags.Enum || t & TypeFlags.NumberLiteral && t & TypeFlags.EnumLiteral)) return true;
18765-
if (s & TypeFlags.NumberLiteral && !(s & TypeFlags.EnumLiteral) &&
18765+
if (s & TypeFlags.NumberLiteral && !(s & TypeFlags.EnumLiteral) && (t & TypeFlags.Enum ||
1876618766
t & TypeFlags.NumberLiteral && t & TypeFlags.EnumLiteral &&
18767-
(source as NumberLiteralType).value === (target as NumberLiteralType).value) return true;
18767+
(source as NumberLiteralType).value === (target as NumberLiteralType).value)) return true;
1876818768
// Anything is assignable to a union containing undefined, null, and {}
1876918769
if (isUnknownLikeUnionType(target)) return true;
1877018770
}

0 commit comments

Comments
 (0)