Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(50375): Errors for missing enum-named properties should attempt t…
…o preserve names (#50382) * fix(50375): preserve enum-named properties * add AllowComputedPropertyEnums option * use bit shifting * rename AllowComputedPropertyEnum -> WriteComputedProps * mark WriteComputedProps as internal * mark symbolToNode as internal
- Loading branch information
1 parent
fb717df
commit 8d7ad8c
Showing
9 changed files
with
112 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/assignmentCompatWithEnumIndexer.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithEnumIndexer.ts(5,5): error TS2741: Property '[E.A]' is missing in type '{}' but required in type 'Record<E, any>'. | ||
|
||
|
||
==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithEnumIndexer.ts (1 errors) ==== | ||
enum E { | ||
A | ||
} | ||
|
||
let foo: Record<E, any> = {} | ||
~~~ | ||
!!! error TS2741: Property '[E.A]' is missing in type '{}' but required in type 'Record<E, any>'. | ||
|
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/assignmentCompatWithEnumIndexer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//// [assignmentCompatWithEnumIndexer.ts] | ||
enum E { | ||
A | ||
} | ||
|
||
let foo: Record<E, any> = {} | ||
|
||
|
||
//// [assignmentCompatWithEnumIndexer.js] | ||
var E; | ||
(function (E) { | ||
E[E["A"] = 0] = "A"; | ||
})(E || (E = {})); | ||
var foo = {}; |
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/assignmentCompatWithEnumIndexer.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
=== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithEnumIndexer.ts === | ||
enum E { | ||
>E : Symbol(E, Decl(assignmentCompatWithEnumIndexer.ts, 0, 0)) | ||
|
||
A | ||
>A : Symbol(E.A, Decl(assignmentCompatWithEnumIndexer.ts, 0, 8)) | ||
} | ||
|
||
let foo: Record<E, any> = {} | ||
>foo : Symbol(foo, Decl(assignmentCompatWithEnumIndexer.ts, 4, 3)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>E : Symbol(E, Decl(assignmentCompatWithEnumIndexer.ts, 0, 0)) | ||
|
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/assignmentCompatWithEnumIndexer.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
=== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithEnumIndexer.ts === | ||
enum E { | ||
>E : E | ||
|
||
A | ||
>A : E.A | ||
} | ||
|
||
let foo: Record<E, any> = {} | ||
>foo : Record<E, any> | ||
>{} : {} | ||
|
5 changes: 5 additions & 0 deletions
5
...rmance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithEnumIndexer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum E { | ||
A | ||
} | ||
|
||
let foo: Record<E, any> = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
////enum E { | ||
//// A | ||
////} | ||
////let obj: Record<E, any> = {} | ||
|
||
verify.codeFix({ | ||
index: 0, | ||
description: ts.Diagnostics.Add_missing_properties.message, | ||
newFileContent: | ||
`enum E { | ||
A | ||
} | ||
let obj: Record<E, any> = { | ||
[E.A]: undefined | ||
}`, | ||
}); |