-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #1433 from Microsoft/typeGuardWithAny
Type guards should not affect values of type any
- Loading branch information
Showing
5 changed files
with
56 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
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 @@ | ||
//// [typeGuardsWithAny.ts] | ||
var x: any = { p: 0 }; | ||
if (x instanceof Object) { | ||
x.p; // No error, type any unaffected by type guard | ||
} | ||
else { | ||
x.p; // No error, type any unaffected by type guard | ||
} | ||
|
||
|
||
//// [typeGuardsWithAny.js] | ||
var x = { p: 0 }; | ||
if (x instanceof Object) { | ||
x.p; // No error, type any unaffected by type guard | ||
} | ||
else { | ||
x.p; // No error, type any unaffected by type guard | ||
} |
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 @@ | ||
=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.ts === | ||
var x: any = { p: 0 }; | ||
>x : any | ||
>{ p: 0 } : { p: number; } | ||
>p : number | ||
|
||
if (x instanceof Object) { | ||
>x instanceof Object : boolean | ||
>x : any | ||
>Object : ObjectConstructor | ||
|
||
x.p; // No error, type any unaffected by type guard | ||
>x.p : any | ||
>x : any | ||
>p : any | ||
} | ||
else { | ||
x.p; // No error, type any unaffected by type guard | ||
>x.p : any | ||
>x : any | ||
>p : any | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
tests/cases/conformance/expressions/typeGuards/typeGuardsWithAny.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,7 @@ | ||
var x: any = { p: 0 }; | ||
if (x instanceof Object) { | ||
x.p; // No error, type any unaffected by type guard | ||
} | ||
else { | ||
x.p; // No error, type any unaffected by type guard | ||
} |