Skip to content

Commit 5f0ada1

Browse files
committed
Fix both new enum assignability predicates
And update error reporting baseline (new error is less elaborate)
1 parent 570433e commit 5f0ada1

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6234,13 +6234,15 @@ namespace ts {
62346234
if (source.flags & TypeFlags.Null && (!strictNullChecks || target.flags & TypeFlags.Null)) return true;
62356235
if (relation === assignableRelation || relation === comparableRelation) {
62366236
if (source.flags & TypeFlags.Any) return true;
6237-
if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) && target.flags & TypeFlags.Enum) return true;
6238-
if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) &&
6239-
target.flags & TypeFlags.Union &&
6240-
forEach((target as UnionType).types, t => t.flags & TypeFlags.EnumLike)) return true;
6241-
if (source.flags & (TypeFlags.NumberLiteral | TypeFlags.EnumLiteral) &&
6237+
if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) && target.flags & TypeFlags.EnumLike) return true;
6238+
if (source.flags & TypeFlags.NumberLiteral && target.flags & TypeFlags.EnumLiteral && (<LiteralType>source).text === (<LiteralType>target).text) return true;
6239+
if (source.flags & TypeFlags.EnumLiteral &&
62426240
target.flags & TypeFlags.EnumLiteral &&
6243-
(<LiteralType>source).text === (<LiteralType>target).text) return true;
6241+
(<LiteralType>source).text === (<LiteralType>target).text &&
6242+
(<EnumLiteralType>source).baseType.symbol.name === (<EnumLiteralType>target).baseType.symbol.name &&
6243+
!isConstEnumSymbol((<EnumLiteralType>source).baseType.symbol) && !isConstEnumSymbol((<EnumLiteralType>target).baseType.symbol)) {
6244+
return true;
6245+
}
62446246
}
62456247
return false;
62466248
}

tests/baselines/reference/enumAssignmentCompat3.errors.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tests/cases/compiler/enumAssignmentCompat3.ts(68,1): error TS2322: Type 'Abcd.E' is not assignable to type 'First.E'.
22
Property 'd' is missing in type 'First.E'.
3-
tests/cases/compiler/enumAssignmentCompat3.ts(70,1): error TS2322: Type 'Cd.E' is not assignable to type 'First.E'.
4-
Property 'd' is missing in type 'First.E'.
3+
tests/cases/compiler/enumAssignmentCompat3.ts(70,1): error TS2324: Property 'd' is missing in type 'First.E'.
54
tests/cases/compiler/enumAssignmentCompat3.ts(71,1): error TS2322: Type 'Nope' is not assignable to type 'E'.
65
tests/cases/compiler/enumAssignmentCompat3.ts(75,1): error TS2322: Type 'First.E' is not assignable to type 'Ab.E'.
76
Property 'c' is missing in type 'Ab.E'.
@@ -89,8 +88,7 @@ tests/cases/compiler/enumAssignmentCompat3.ts(86,1): error TS2322: Type 'Merged.
8988
abc = secondAb; // ok
9089
abc = secondCd; // missing 'd'
9190
~~~
92-
!!! error TS2322: Type 'Cd.E' is not assignable to type 'First.E'.
93-
!!! error TS2322: Property 'd' is missing in type 'First.E'.
91+
!!! error TS2324: Property 'd' is missing in type 'First.E'.
9492
abc = nope; // nope!
9593
~~~
9694
!!! error TS2322: Type 'Nope' is not assignable to type 'E'.

0 commit comments

Comments
 (0)