Skip to content

Commit cf7ea8a

Browse files
committed
keep those inferences when "external" candidates are found
1 parent 09e5824 commit cf7ea8a

3 files changed

Lines changed: 59 additions & 55 deletions

File tree

src/compiler/checker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26784,14 +26784,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2678426784
if (candidate === blockedStringType) {
2678526785
return;
2678626786
}
26787-
const combinedPriority = priority | (inference.individualPriority || InferencePriority.None)
26788-
if (inference.priority === undefined || combinedPriority < inference.priority) {
26787+
const combinedPriority = priority | (inference.individualPriority || InferencePriority.None);
26788+
if (inference.priority === undefined || priority < (inference.priority & ~InferencePriority.DistributiveConditional)) {
2678926789
inference.candidates = undefined;
2679026790
inference.contraCandidates = undefined;
2679126791
inference.topLevel = true;
2679226792
inference.priority = combinedPriority;
2679326793
}
26794-
if (combinedPriority === inference.priority) {
26794+
if (priority === (inference.priority & ~InferencePriority.DistributiveConditional)) {
26795+
if (inference.priority !== combinedPriority) {
26796+
inference.priority = combinedPriority;
26797+
clearCachedInferences(inferences);
26798+
}
2679526799
// We make contravariant inferences only if we are in a pure contravariant position,
2679626800
// i.e. only if we have not descended into a bivariant position.
2679726801
if (contravariant && !bivariant) {

tests/baselines/reference/typePredicateFreshLiteralWidening.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ const values1 = [item1, item2, item3].map(item => item.value);
8888
>item3 : Symbol(item3, Decl(typePredicateFreshLiteralWidening.ts, 19, 5))
8989
>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --))
9090
>item : Symbol(item, Decl(typePredicateFreshLiteralWidening.ts, 24, 42))
91-
>item.value : Symbol(value, Decl(typePredicateFreshLiteralWidening.ts, 15, 13))
91+
>item.value : Symbol(value, Decl(typePredicateFreshLiteralWidening.ts, 17, 33), Decl(typePredicateFreshLiteralWidening.ts, 18, 33), Decl(typePredicateFreshLiteralWidening.ts, 19, 33))
9292
>item : Symbol(item, Decl(typePredicateFreshLiteralWidening.ts, 24, 42))
93-
>value : Symbol(value, Decl(typePredicateFreshLiteralWidening.ts, 15, 13))
93+
>value : Symbol(value, Decl(typePredicateFreshLiteralWidening.ts, 17, 33), Decl(typePredicateFreshLiteralWidening.ts, 18, 33), Decl(typePredicateFreshLiteralWidening.ts, 19, 33))
9494

9595
const filteredValues1 = values1.filter(isNotNull);
9696
>filteredValues1 : Symbol(filteredValues1, Decl(typePredicateFreshLiteralWidening.ts, 25, 5))

tests/baselines/reference/typePredicateFreshLiteralWidening.types

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,34 @@ type Item = { value: string | null };
5151
> : ^^^^^^^^^^^^^
5252

5353
const item1 = satisfies<Item>()({ value: "1" });
54-
>item1 : { value: Narrow<string | null>; }
55-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56-
>satisfies<Item>()({ value: "1" }) : { value: Narrow<string | null>; }
57-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
>item1 : { value: "1"; }
55+
> : ^^^^^^^^^^^^^^^
56+
>satisfies<Item>()({ value: "1" }) : { value: "1"; }
57+
> : ^^^^^^^^^^^^^^^
5858
>satisfies<Item>() : <TNarrow extends Item>(narrow: Narrow<TNarrow>) => Narrow<TNarrow>
5959
> : ^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060
>satisfies : <TWide>() => <TNarrow extends TWide>(narrow: Narrow<TNarrow>) => Narrow<TNarrow>
6161
> : ^ ^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^
62-
>{ value: "1" } : { value: string; }
63-
> : ^^^^^^^^^^^^^^^^^^
64-
>value : string
65-
> : ^^^^^^
62+
>{ value: "1" } : { value: "1"; }
63+
> : ^^^^^^^^^^^^^^^
64+
>value : "1"
65+
> : ^^^
6666
>"1" : "1"
6767
> : ^^^
6868

6969
const item2 = satisfies<Item>()({ value: "2" });
70-
>item2 : { value: Narrow<string | null>; }
71-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72-
>satisfies<Item>()({ value: "2" }) : { value: Narrow<string | null>; }
73-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
>item2 : { value: "2"; }
71+
> : ^^^^^^^^^^^^^^^
72+
>satisfies<Item>()({ value: "2" }) : { value: "2"; }
73+
> : ^^^^^^^^^^^^^^^
7474
>satisfies<Item>() : <TNarrow extends Item>(narrow: Narrow<TNarrow>) => Narrow<TNarrow>
7575
> : ^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7676
>satisfies : <TWide>() => <TNarrow extends TWide>(narrow: Narrow<TNarrow>) => Narrow<TNarrow>
7777
> : ^ ^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^
78-
>{ value: "2" } : { value: string; }
79-
> : ^^^^^^^^^^^^^^^^^^
80-
>value : string
81-
> : ^^^^^^
78+
>{ value: "2" } : { value: "2"; }
79+
> : ^^^^^^^^^^^^^^^
80+
>value : "2"
81+
> : ^^^
8282
>"2" : "2"
8383
> : ^^^
8484

@@ -121,44 +121,44 @@ const filteredValues2 = values2.filter(isNotNull);
121121
> : ^ ^^ ^^ ^^^^^
122122

123123
const values1 = [item1, item2, item3].map(item => item.value);
124-
>values1 : Narrow<string | null>[]
125-
> : ^^^^^^^^^^^^^^^^^^^^^^^
126-
>[item1, item2, item3].map(item => item.value) : Narrow<string | null>[]
127-
> : ^^^^^^^^^^^^^^^^^^^^^^^
128-
>[item1, item2, item3].map : <U>(callbackfn: (value: { value: Narrow<string | null>; }, index: number, array: { value: Narrow<string | null>; }[]) => U, thisArg?: any) => U[]
129-
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
130-
>[item1, item2, item3] : { value: Narrow<string | null>; }[]
131-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132-
>item1 : { value: Narrow<string | null>; }
133-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134-
>item2 : { value: Narrow<string | null>; }
135-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124+
>values1 : ("1" | "2" | null)[]
125+
> : ^^^^^^^^^^^^^^^^^^^^
126+
>[item1, item2, item3].map(item => item.value) : ("1" | "2" | null)[]
127+
> : ^^^^^^^^^^^^^^^^^^^^
128+
>[item1, item2, item3].map : <U>(callbackfn: (value: { value: "1"; } | { value: "2"; } | { value: null; }, index: number, array: ({ value: "1"; } | { value: "2"; } | { value: null; })[]) => U, thisArg?: any) => U[]
129+
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
130+
>[item1, item2, item3] : ({ value: "1"; } | { value: "2"; } | { value: null; })[]
131+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
>item1 : { value: "1"; }
133+
> : ^^^^^^^^^^^^^^^
134+
>item2 : { value: "2"; }
135+
> : ^^^^^^^^^^^^^^^
136136
>item3 : { value: null; }
137137
> : ^^^^^^^^^^^^^^^^
138-
>map : <U>(callbackfn: (value: { value: Narrow<string | null>; }, index: number, array: { value: Narrow<string | null>; }[]) => U, thisArg?: any) => U[]
139-
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
140-
>item => item.value : (item: { value: Narrow<string | null>; }) => Narrow<string | null>
141-
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
142-
>item : { value: Narrow<string | null>; }
143-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144-
>item.value : Narrow<string | null>
145-
> : ^^^^^^^^^^^^^^^^^^^^^
146-
>item : { value: Narrow<string | null>; }
147-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148-
>value : Narrow<string | null>
149-
> : ^^^^^^^^^^^^^^^^^^^^^
138+
>map : <U>(callbackfn: (value: { value: "1"; } | { value: "2"; } | { value: null; }, index: number, array: ({ value: "1"; } | { value: "2"; } | { value: null; })[]) => U, thisArg?: any) => U[]
139+
> : ^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^
140+
>item => item.value : (item: { value: "1"; } | { value: "2"; } | { value: null; }) => "1" | "2" | null
141+
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
142+
>item : { value: "1"; } | { value: "2"; } | { value: null; }
143+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144+
>item.value : "1" | "2" | null
145+
> : ^^^^^^^^^^^^^^^^
146+
>item : { value: "1"; } | { value: "2"; } | { value: null; }
147+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148+
>value : "1" | "2" | null
149+
> : ^^^^^^^^^^^^^^^^
150150

151151
const filteredValues1 = values1.filter(isNotNull);
152-
>filteredValues1 : string[]
153-
> : ^^^^^^^^
154-
>values1.filter(isNotNull) : string[]
155-
> : ^^^^^^^^
156-
>values1.filter : { <S extends Narrow<string | null>>(predicate: (value: Narrow<string | null>, index: number, array: Narrow<string | null>[]) => value is S, thisArg?: any): S[]; (predicate: (value: Narrow<string | null>, index: number, array: Narrow<string | null>[]) => unknown, thisArg?: any): Narrow<string | null>[]; }
157-
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158-
>values1 : Narrow<string | null>[]
159-
> : ^^^^^^^^^^^^^^^^^^^^^^^
160-
>filter : { <S extends Narrow<string | null>>(predicate: (value: Narrow<string | null>, index: number, array: Narrow<string | null>[]) => value is S, thisArg?: any): S[]; (predicate: (value: Narrow<string | null>, index: number, array: Narrow<string | null>[]) => unknown, thisArg?: any): Narrow<string | null>[]; }
161-
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152+
>filteredValues1 : ("1" | "2")[]
153+
> : ^^^^^^^^^^^^^
154+
>values1.filter(isNotNull) : ("1" | "2")[]
155+
> : ^^^^^^^^^^^^^
156+
>values1.filter : { <S extends "1" | "2" | null>(predicate: (value: "1" | "2" | null, index: number, array: ("1" | "2" | null)[]) => value is S, thisArg?: any): S[]; (predicate: (value: "1" | "2" | null, index: number, array: ("1" | "2" | null)[]) => unknown, thisArg?: any): ("1" | "2" | null)[]; }
157+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
158+
>values1 : ("1" | "2" | null)[]
159+
> : ^^^^^^^^^^^^^^^^^^^^
160+
>filter : { <S extends "1" | "2" | null>(predicate: (value: "1" | "2" | null, index: number, array: ("1" | "2" | null)[]) => value is S, thisArg?: any): S[]; (predicate: (value: "1" | "2" | null, index: number, array: ("1" | "2" | null)[]) => unknown, thisArg?: any): ("1" | "2" | null)[]; }
161+
> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
162162
>isNotNull : <T>(value: T | null) => value is T
163163
> : ^ ^^ ^^ ^^^^^
164164

0 commit comments

Comments
 (0)