-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
854d448
commit 856c7c5
Showing
8 changed files
with
942 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
139 changes: 139 additions & 0 deletions
139
tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).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,139 @@ | ||
//// [emptyAnonymousObjectNarrowing.ts] | ||
declare let nonNull: {}; | ||
if (nonNull === "foo") { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
|
||
declare let obj: { a: string }; | ||
if (nonNull === obj) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
|
||
function f1<T>(x: T) { | ||
if (nonNull === x) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
} | ||
|
||
function f2<T extends object>(x: T) { | ||
if (nonNull === x) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
} | ||
|
||
declare let union: "xyz" | { a: string } | undefined; | ||
if (nonNull === union) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
|
||
if (nonNull === undefined) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
|
||
if (nonNull === null) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
|
||
if (nonNull == undefined) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
|
||
// Repro from #50567 | ||
const foo = (value: unknown): string => { | ||
if (!value) { | ||
return 'foo'; | ||
} | ||
if (value === 'xyz') { | ||
return value; // Type '{}' is not assignable to type 'string'. | ||
} | ||
return ''; | ||
}; | ||
|
||
|
||
//// [emptyAnonymousObjectNarrowing.js] | ||
if (nonNull === "foo") { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
if (nonNull === obj) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
function f1(x) { | ||
if (nonNull === x) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
} | ||
function f2(x) { | ||
if (nonNull === x) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
} | ||
if (nonNull === union) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
if (nonNull === undefined) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
if (nonNull === null) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
if (nonNull == undefined) { | ||
nonNull; | ||
} | ||
else { | ||
nonNull; | ||
} | ||
// Repro from #50567 | ||
var foo = function (value) { | ||
if (!value) { | ||
return 'foo'; | ||
} | ||
if (value === 'xyz') { | ||
return value; // Type '{}' is not assignable to type 'string'. | ||
} | ||
return ''; | ||
}; |
139 changes: 139 additions & 0 deletions
139
tests/baselines/reference/emptyAnonymousObjectNarrowing(strictnullchecks=false).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,139 @@ | ||
=== tests/cases/compiler/emptyAnonymousObjectNarrowing.ts === | ||
declare let nonNull: {}; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
|
||
if (nonNull === "foo") { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
|
||
declare let obj: { a: string }; | ||
>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) | ||
>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 8, 18)) | ||
|
||
if (nonNull === obj) { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
>obj : Symbol(obj, Decl(emptyAnonymousObjectNarrowing.ts, 8, 11)) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
|
||
function f1<T>(x: T) { | ||
>f1 : Symbol(f1, Decl(emptyAnonymousObjectNarrowing.ts, 14, 1)) | ||
>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) | ||
>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) | ||
>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 16, 12)) | ||
|
||
if (nonNull === x) { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 16, 15)) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
} | ||
|
||
function f2<T extends object>(x: T) { | ||
>f2 : Symbol(f2, Decl(emptyAnonymousObjectNarrowing.ts, 23, 1)) | ||
>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) | ||
>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) | ||
>T : Symbol(T, Decl(emptyAnonymousObjectNarrowing.ts, 25, 12)) | ||
|
||
if (nonNull === x) { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
>x : Symbol(x, Decl(emptyAnonymousObjectNarrowing.ts, 25, 30)) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
} | ||
|
||
declare let union: "xyz" | { a: string } | undefined; | ||
>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) | ||
>a : Symbol(a, Decl(emptyAnonymousObjectNarrowing.ts, 34, 28)) | ||
|
||
if (nonNull === union) { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
>union : Symbol(union, Decl(emptyAnonymousObjectNarrowing.ts, 34, 11)) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
|
||
if (nonNull === undefined) { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
>undefined : Symbol(undefined) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
|
||
if (nonNull === null) { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
|
||
if (nonNull == undefined) { | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
>undefined : Symbol(undefined) | ||
|
||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
else { | ||
nonNull; | ||
>nonNull : Symbol(nonNull, Decl(emptyAnonymousObjectNarrowing.ts, 0, 11)) | ||
} | ||
|
||
// Repro from #50567 | ||
const foo = (value: unknown): string => { | ||
>foo : Symbol(foo, Decl(emptyAnonymousObjectNarrowing.ts, 64, 5)) | ||
>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) | ||
|
||
if (!value) { | ||
>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) | ||
|
||
return 'foo'; | ||
} | ||
if (value === 'xyz') { | ||
>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) | ||
|
||
return value; // Type '{}' is not assignable to type 'string'. | ||
>value : Symbol(value, Decl(emptyAnonymousObjectNarrowing.ts, 64, 13)) | ||
} | ||
return ''; | ||
}; | ||
|
Oops, something went wrong.