-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Allow (non-assert) type predicates to narrow by discriminant"… (
- Loading branch information
Showing
8 changed files
with
434 additions
and
61 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
69 changes: 69 additions & 0 deletions
69
tests/baselines/reference/discriminantNarrowingCouldBeCircular.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,69 @@ | ||
//// [tests/cases/compiler/discriminantNarrowingCouldBeCircular.ts] //// | ||
|
||
//// [discriminantNarrowingCouldBeCircular.ts] | ||
// #57705, 57690 | ||
declare function is<T>(v: T): v is T; | ||
const o: Record<string, string> | undefined = {}; | ||
if (o) { | ||
for (const key in o) { | ||
const value = o[key]; | ||
if (is<string>(value)) { | ||
} | ||
} | ||
} | ||
|
||
type SomeRecord = { a: string }; | ||
declare const kPresentationInheritanceParents: { [tagName: string]: string[] }; | ||
declare function parentElementOrShadowHost(element: SomeRecord): SomeRecord | undefined; | ||
|
||
function getImplicitAriaRole(element: SomeRecord) { | ||
let ancestor: SomeRecord | null = element; | ||
while (ancestor) { | ||
const parent = parentElementOrShadowHost(ancestor); | ||
const parents = kPresentationInheritanceParents[ancestor.a]; | ||
if (!parents || !parent || !parents.includes(parent.a)) | ||
break; | ||
ancestor = parent; | ||
} | ||
} | ||
|
||
declare function isPlainObject2<T>( | ||
data: unknown, | ||
): data is Record<PropertyKey, unknown>; | ||
|
||
declare const myObj2: unknown; | ||
if (isPlainObject2(myObj2)) { | ||
for (const key of ["a", "b", "c"]) { | ||
const deeper = myObj2[key]; | ||
const deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
} | ||
} | ||
|
||
|
||
//// [discriminantNarrowingCouldBeCircular.js] | ||
"use strict"; | ||
var o = {}; | ||
if (o) { | ||
for (var key in o) { | ||
var value = o[key]; | ||
if (is(value)) { | ||
} | ||
} | ||
} | ||
function getImplicitAriaRole(element) { | ||
var ancestor = element; | ||
while (ancestor) { | ||
var parent = parentElementOrShadowHost(ancestor); | ||
var parents = kPresentationInheritanceParents[ancestor.a]; | ||
if (!parents || !parent || !parents.includes(parent.a)) | ||
break; | ||
ancestor = parent; | ||
} | ||
} | ||
if (isPlainObject2(myObj2)) { | ||
for (var _i = 0, _a = ["a", "b", "c"]; _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var deeper = myObj2[key]; | ||
var deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
tests/baselines/reference/discriminantNarrowingCouldBeCircular.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,129 @@ | ||
//// [tests/cases/compiler/discriminantNarrowingCouldBeCircular.ts] //// | ||
|
||
=== discriminantNarrowingCouldBeCircular.ts === | ||
// #57705, 57690 | ||
declare function is<T>(v: T): v is T; | ||
>is : Symbol(is, Decl(discriminantNarrowingCouldBeCircular.ts, 0, 0)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 20)) | ||
>v : Symbol(v, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 23)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 20)) | ||
>v : Symbol(v, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 23)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 20)) | ||
|
||
const o: Record<string, string> | undefined = {}; | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
|
||
if (o) { | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
|
||
for (const key in o) { | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 4, 12)) | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
|
||
const value = o[key]; | ||
>value : Symbol(value, Decl(discriminantNarrowingCouldBeCircular.ts, 5, 9)) | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 4, 12)) | ||
|
||
if (is<string>(value)) { | ||
>is : Symbol(is, Decl(discriminantNarrowingCouldBeCircular.ts, 0, 0)) | ||
>value : Symbol(value, Decl(discriminantNarrowingCouldBeCircular.ts, 5, 9)) | ||
} | ||
} | ||
} | ||
|
||
type SomeRecord = { a: string }; | ||
>SomeRecord : Symbol(SomeRecord, Decl(discriminantNarrowingCouldBeCircular.ts, 9, 1)) | ||
>a : Symbol(a, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 19)) | ||
|
||
declare const kPresentationInheritanceParents: { [tagName: string]: string[] }; | ||
>kPresentationInheritanceParents : Symbol(kPresentationInheritanceParents, Decl(discriminantNarrowingCouldBeCircular.ts, 12, 13)) | ||
>tagName : Symbol(tagName, Decl(discriminantNarrowingCouldBeCircular.ts, 12, 50)) | ||
|
||
declare function parentElementOrShadowHost(element: SomeRecord): SomeRecord | undefined; | ||
>parentElementOrShadowHost : Symbol(parentElementOrShadowHost, Decl(discriminantNarrowingCouldBeCircular.ts, 12, 79)) | ||
>element : Symbol(element, Decl(discriminantNarrowingCouldBeCircular.ts, 13, 43)) | ||
>SomeRecord : Symbol(SomeRecord, Decl(discriminantNarrowingCouldBeCircular.ts, 9, 1)) | ||
>SomeRecord : Symbol(SomeRecord, Decl(discriminantNarrowingCouldBeCircular.ts, 9, 1)) | ||
|
||
function getImplicitAriaRole(element: SomeRecord) { | ||
>getImplicitAriaRole : Symbol(getImplicitAriaRole, Decl(discriminantNarrowingCouldBeCircular.ts, 13, 88)) | ||
>element : Symbol(element, Decl(discriminantNarrowingCouldBeCircular.ts, 15, 29)) | ||
>SomeRecord : Symbol(SomeRecord, Decl(discriminantNarrowingCouldBeCircular.ts, 9, 1)) | ||
|
||
let ancestor: SomeRecord | null = element; | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 16, 5)) | ||
>SomeRecord : Symbol(SomeRecord, Decl(discriminantNarrowingCouldBeCircular.ts, 9, 1)) | ||
>element : Symbol(element, Decl(discriminantNarrowingCouldBeCircular.ts, 15, 29)) | ||
|
||
while (ancestor) { | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 16, 5)) | ||
|
||
const parent = parentElementOrShadowHost(ancestor); | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 18, 9)) | ||
>parentElementOrShadowHost : Symbol(parentElementOrShadowHost, Decl(discriminantNarrowingCouldBeCircular.ts, 12, 79)) | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 16, 5)) | ||
|
||
const parents = kPresentationInheritanceParents[ancestor.a]; | ||
>parents : Symbol(parents, Decl(discriminantNarrowingCouldBeCircular.ts, 19, 9)) | ||
>kPresentationInheritanceParents : Symbol(kPresentationInheritanceParents, Decl(discriminantNarrowingCouldBeCircular.ts, 12, 13)) | ||
>ancestor.a : Symbol(a, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 19)) | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 16, 5)) | ||
>a : Symbol(a, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 19)) | ||
|
||
if (!parents || !parent || !parents.includes(parent.a)) | ||
>parents : Symbol(parents, Decl(discriminantNarrowingCouldBeCircular.ts, 19, 9)) | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 18, 9)) | ||
>parents.includes : Symbol(Array.includes, Decl(lib.es2016.array.include.d.ts, --, --)) | ||
>parents : Symbol(parents, Decl(discriminantNarrowingCouldBeCircular.ts, 19, 9)) | ||
>includes : Symbol(Array.includes, Decl(lib.es2016.array.include.d.ts, --, --)) | ||
>parent.a : Symbol(a, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 19)) | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 18, 9)) | ||
>a : Symbol(a, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 19)) | ||
|
||
break; | ||
ancestor = parent; | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 16, 5)) | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 18, 9)) | ||
} | ||
} | ||
|
||
declare function isPlainObject2<T>( | ||
>isPlainObject2 : Symbol(isPlainObject2, Decl(discriminantNarrowingCouldBeCircular.ts, 24, 1)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 26, 32)) | ||
|
||
data: unknown, | ||
>data : Symbol(data, Decl(discriminantNarrowingCouldBeCircular.ts, 26, 35)) | ||
|
||
): data is Record<PropertyKey, unknown>; | ||
>data : Symbol(data, Decl(discriminantNarrowingCouldBeCircular.ts, 26, 35)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) | ||
|
||
declare const myObj2: unknown; | ||
>myObj2 : Symbol(myObj2, Decl(discriminantNarrowingCouldBeCircular.ts, 30, 15)) | ||
|
||
if (isPlainObject2(myObj2)) { | ||
>isPlainObject2 : Symbol(isPlainObject2, Decl(discriminantNarrowingCouldBeCircular.ts, 24, 1)) | ||
>myObj2 : Symbol(myObj2, Decl(discriminantNarrowingCouldBeCircular.ts, 30, 15)) | ||
|
||
for (const key of ["a", "b", "c"]) { | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 32, 16)) | ||
|
||
const deeper = myObj2[key]; | ||
>deeper : Symbol(deeper, Decl(discriminantNarrowingCouldBeCircular.ts, 33, 13)) | ||
>myObj2 : Symbol(myObj2, Decl(discriminantNarrowingCouldBeCircular.ts, 30, 15)) | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 32, 16)) | ||
|
||
const deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
>deeperKeys : Symbol(deeperKeys, Decl(discriminantNarrowingCouldBeCircular.ts, 34, 13)) | ||
>isPlainObject2 : Symbol(isPlainObject2, Decl(discriminantNarrowingCouldBeCircular.ts, 24, 1)) | ||
>deeper : Symbol(deeper, Decl(discriminantNarrowingCouldBeCircular.ts, 33, 13)) | ||
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
>deeper : Symbol(deeper, Decl(discriminantNarrowingCouldBeCircular.ts, 33, 13)) | ||
} | ||
} | ||
|
Oops, something went wrong.