forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request microsoft#19838 from Microsoft/narrow-index-signat…
…ure-property-access Narrow property access of undeclared properties from string index signatures
- Loading branch information
Showing
5 changed files
with
120 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//// [controlFlowStringIndex.ts] | ||
type A = { | ||
other: number | null; | ||
[index: string]: number | null | ||
}; | ||
declare const value: A; | ||
if (value.foo !== null) { | ||
value.foo.toExponential() | ||
value.other // should still be number | null | ||
value.bar // should still be number | null | ||
} | ||
|
||
|
||
//// [controlFlowStringIndex.js] | ||
"use strict"; | ||
if (value.foo !== null) { | ||
value.foo.toExponential(); | ||
value.other; // should still be number | null | ||
value.bar; // should still be number | null | ||
} |
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,32 @@ | ||
=== tests/cases/conformance/controlFlow/controlFlowStringIndex.ts === | ||
type A = { | ||
>A : Symbol(A, Decl(controlFlowStringIndex.ts, 0, 0)) | ||
|
||
other: number | null; | ||
>other : Symbol(other, Decl(controlFlowStringIndex.ts, 0, 10)) | ||
|
||
[index: string]: number | null | ||
>index : Symbol(index, Decl(controlFlowStringIndex.ts, 2, 5)) | ||
|
||
}; | ||
declare const value: A; | ||
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 4, 13)) | ||
>A : Symbol(A, Decl(controlFlowStringIndex.ts, 0, 0)) | ||
|
||
if (value.foo !== null) { | ||
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 4, 13)) | ||
|
||
value.foo.toExponential() | ||
>value.foo.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) | ||
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 4, 13)) | ||
>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) | ||
|
||
value.other // should still be number | null | ||
>value.other : Symbol(other, Decl(controlFlowStringIndex.ts, 0, 10)) | ||
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 4, 13)) | ||
>other : Symbol(other, Decl(controlFlowStringIndex.ts, 0, 10)) | ||
|
||
value.bar // should still be number | null | ||
>value : Symbol(value, Decl(controlFlowStringIndex.ts, 4, 13)) | ||
} | ||
|
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,43 @@ | ||
=== tests/cases/conformance/controlFlow/controlFlowStringIndex.ts === | ||
type A = { | ||
>A : A | ||
|
||
other: number | null; | ||
>other : number | null | ||
>null : null | ||
|
||
[index: string]: number | null | ||
>index : string | ||
>null : null | ||
|
||
}; | ||
declare const value: A; | ||
>value : A | ||
>A : A | ||
|
||
if (value.foo !== null) { | ||
>value.foo !== null : boolean | ||
>value.foo : number | null | ||
>value : A | ||
>foo : number | null | ||
>null : null | ||
|
||
value.foo.toExponential() | ||
>value.foo.toExponential() : string | ||
>value.foo.toExponential : (fractionDigits?: number | undefined) => string | ||
>value.foo : number | ||
>value : A | ||
>foo : number | ||
>toExponential : (fractionDigits?: number | undefined) => string | ||
|
||
value.other // should still be number | null | ||
>value.other : number | null | ||
>value : A | ||
>other : number | null | ||
|
||
value.bar // should still be number | null | ||
>value.bar : number | null | ||
>value : A | ||
>bar : number | null | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
tests/cases/conformance/controlFlow/controlFlowStringIndex.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,11 @@ | ||
// @strict: true | ||
type A = { | ||
other: number | null; | ||
[index: string]: number | null | ||
}; | ||
declare const value: A; | ||
if (value.foo !== null) { | ||
value.foo.toExponential() | ||
value.other // should still be number | null | ||
value.bar // should still be number | null | ||
} |