mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Number is assignable to enum, even inside union
Previously, numbers were not assignable to enums that were inside a union
This commit is contained in:
parent
d248358e9c
commit
3b40affeb7
@ -6235,6 +6235,9 @@ namespace ts {
|
||||
if (relation === assignableRelation || relation === comparableRelation) {
|
||||
if (source.flags & TypeFlags.Any) return true;
|
||||
if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) && target.flags & TypeFlags.Enum) return true;
|
||||
if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) &&
|
||||
target.flags & TypeFlags.Union &&
|
||||
forEach((target as UnionType).types, t => t.flags & TypeFlags.EnumLike)) return true;
|
||||
if (source.flags & TypeFlags.NumberLiteral && target.flags & TypeFlags.EnumLiteral && (<LiteralType>source).text === (<LiteralType>target).text) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user