Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix(49594): Typescript 4.7.3 bracketed class property compilation err…
…or strictPropertyInitialization:true (#49619) * fix(49594): allow enum members in computed properties * add additional tests * handle enum members without initializers * update tests
- Loading branch information
Showing
14 changed files
with
306 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//// [typeGuardNarrowsIndexedAccessOfKnownProperty11.ts] | ||
enum E { A, B } | ||
|
||
declare const m: { [K in E]: string | null }; | ||
|
||
if (m[E.A] !== null) { | ||
m[E.A].toString(); // string | ||
} | ||
|
||
|
||
//// [typeGuardNarrowsIndexedAccessOfKnownProperty11.js] | ||
"use strict"; | ||
var E; | ||
(function (E) { | ||
E[E["A"] = 0] = "A"; | ||
E[E["B"] = 1] = "B"; | ||
})(E || (E = {})); | ||
if (m[E.A] !== null) { | ||
m[E.A].toString(); // string | ||
} |
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,26 @@ | ||
=== tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty11.ts === | ||
enum E { A, B } | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 0)) | ||
>A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 8)) | ||
>B : Symbol(E.B, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 11)) | ||
|
||
declare const m: { [K in E]: string | null }; | ||
>m : Symbol(m, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 2, 13)) | ||
>K : Symbol(K, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 2, 20)) | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 0)) | ||
|
||
if (m[E.A] !== null) { | ||
>m : Symbol(m, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 2, 13)) | ||
>E.A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 8)) | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 0)) | ||
>A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 8)) | ||
|
||
m[E.A].toString(); // string | ||
>m[E.A].toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --)) | ||
>m : Symbol(m, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 2, 13)) | ||
>E.A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 8)) | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 0)) | ||
>A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty11.ts, 0, 8)) | ||
>toString : Symbol(String.toString, Decl(lib.es5.d.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,30 @@ | ||
=== tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty11.ts === | ||
enum E { A, B } | ||
>E : E | ||
>A : E.A | ||
>B : E.B | ||
|
||
declare const m: { [K in E]: string | null }; | ||
>m : { 0: string | null; 1: string | null; } | ||
>null : null | ||
|
||
if (m[E.A] !== null) { | ||
>m[E.A] !== null : boolean | ||
>m[E.A] : string | null | ||
>m : { 0: string | null; 1: string | null; } | ||
>E.A : E.A | ||
>E : typeof E | ||
>A : E.A | ||
>null : null | ||
|
||
m[E.A].toString(); // string | ||
>m[E.A].toString() : string | ||
>m[E.A].toString : () => string | ||
>m[E.A] : string | ||
>m : { 0: string | null; 1: string | null; } | ||
>E.A : E.A | ||
>E : typeof E | ||
>A : E.A | ||
>toString : () => string | ||
} | ||
|
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,23 @@ | ||
//// [typeGuardNarrowsIndexedAccessOfKnownProperty12.ts] | ||
enum E { | ||
A = "A", | ||
B = "B" | ||
} | ||
|
||
declare const m: { [K in E]: string | null }; | ||
|
||
if (m[E.A] !== null) { | ||
m[E.A].toString(); // string | ||
} | ||
|
||
|
||
//// [typeGuardNarrowsIndexedAccessOfKnownProperty12.js] | ||
"use strict"; | ||
var E; | ||
(function (E) { | ||
E["A"] = "A"; | ||
E["B"] = "B"; | ||
})(E || (E = {})); | ||
if (m[E.A] !== null) { | ||
m[E.A].toString(); // string | ||
} |
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,31 @@ | ||
=== tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty12.ts === | ||
enum E { | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 0)) | ||
|
||
A = "A", | ||
>A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 8)) | ||
|
||
B = "B" | ||
>B : Symbol(E.B, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 1, 12)) | ||
} | ||
|
||
declare const m: { [K in E]: string | null }; | ||
>m : Symbol(m, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 5, 13)) | ||
>K : Symbol(K, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 5, 20)) | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 0)) | ||
|
||
if (m[E.A] !== null) { | ||
>m : Symbol(m, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 5, 13)) | ||
>E.A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 8)) | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 0)) | ||
>A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 8)) | ||
|
||
m[E.A].toString(); // string | ||
>m[E.A].toString : Symbol(String.toString, Decl(lib.es5.d.ts, --, --)) | ||
>m : Symbol(m, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 5, 13)) | ||
>E.A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 8)) | ||
>E : Symbol(E, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 0)) | ||
>A : Symbol(E.A, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty12.ts, 0, 8)) | ||
>toString : Symbol(String.toString, Decl(lib.es5.d.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,37 @@ | ||
=== tests/cases/compiler/typeGuardNarrowsIndexedAccessOfKnownProperty12.ts === | ||
enum E { | ||
>E : E | ||
|
||
A = "A", | ||
>A : E.A | ||
>"A" : "A" | ||
|
||
B = "B" | ||
>B : E.B | ||
>"B" : "B" | ||
} | ||
|
||
declare const m: { [K in E]: string | null }; | ||
>m : { A: string | null; B: string | null; } | ||
>null : null | ||
|
||
if (m[E.A] !== null) { | ||
>m[E.A] !== null : boolean | ||
>m[E.A] : string | null | ||
>m : { A: string | null; B: string | null; } | ||
>E.A : E.A | ||
>E : typeof E | ||
>A : E.A | ||
>null : null | ||
|
||
m[E.A].toString(); // string | ||
>m[E.A].toString() : string | ||
>m[E.A].toString : () => string | ||
>m[E.A] : string | ||
>m : { A: string | null; B: string | null; } | ||
>E.A : E.A | ||
>E : typeof E | ||
>A : E.A | ||
>toString : () => string | ||
} | ||
|
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,9 @@ | ||
// @strict: true | ||
|
||
enum E { A, B } | ||
|
||
declare const m: { [K in E]: string | null }; | ||
|
||
if (m[E.A] !== null) { | ||
m[E.A].toString(); // string | ||
} |
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 @@ | ||
// @strict: true | ||
|
||
enum E { | ||
A = "A", | ||
B = "B" | ||
} | ||
|
||
declare const m: { [K in E]: string | null }; | ||
|
||
if (m[E.A] !== null) { | ||
m[E.A].toString(); // string | ||
} |
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