Skip to content

Commit 0396723

Browse files
authored
Revert "Stop looking at binding patterns for type argument inference" (#46013)
* Revert "Stop looking at binding patterns for type argument inference (#45719)" This reverts commit be618b1. * Update error baseline for moved lib file declaration
1 parent efbce10 commit 0396723

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25445,8 +25445,7 @@ namespace ts {
2544525445
if (result) {
2544625446
return result;
2544725447
}
25448-
if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name)) {
25449-
// This is less a contextual type and more an implied shape - in some cases, this may be undesirable
25448+
if (!(contextFlags! & ContextFlags.SkipBindingPatterns) && isBindingPattern(declaration.name)) { // This is less a contextual type and more an implied shape - in some cases, this may be undesirable
2545025449
return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
2545125450
}
2545225451
}
@@ -28753,7 +28752,7 @@ namespace ts {
2875328752
// 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
2875428753
// return type of 'wrap'.
2875528754
if (node.kind !== SyntaxKind.Decorator) {
28756-
const contextualType = getContextualType(node, ContextFlags.SkipBindingPatterns);
28755+
const contextualType = getContextualType(node, every(signature.typeParameters, p => !!getDefaultFromTypeParameter(p)) ? ContextFlags.SkipBindingPatterns : ContextFlags.None);
2875728756
if (contextualType) {
2875828757
// We clone the inference context to avoid disturbing a resolution in progress for an
2875928758
// outer call expression. Effectively we just want a snapshot of whatever has been

tests/baselines/reference/destructuringTuple.errors.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
tests/cases/compiler/destructuringTuple.ts(11,7): error TS2461: Type 'number' is not an array type.
2+
tests/cases/compiler/destructuringTuple.ts(11,48): error TS2769: No overload matches this call.
3+
Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
4+
Type 'never[]' is not assignable to type 'number'.
5+
Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
6+
Type 'never[]' is not assignable to type '[]'.
7+
Target allows only 0 element(s) but source may have more.
18
tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload matches this call.
29
Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
310
Argument of type 'number' is not assignable to parameter of type 'ConcatArray<never>'.
411
Overload 2 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
512
Argument of type 'number' is not assignable to parameter of type 'ConcatArray<never>'.
613

714

8-
==== tests/cases/compiler/destructuringTuple.ts (1 errors) ====
15+
==== tests/cases/compiler/destructuringTuple.ts (3 errors) ====
916
declare var tuple: [boolean, number, ...string[]];
1017

1118
const [a, b, c, ...rest] = tuple;
@@ -17,6 +24,17 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat
1724
// Repros from #32140
1825

1926
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
27+
~~~~~~~
28+
!!! error TS2461: Type 'number' is not an array type.
29+
~~~~~~~~~~~~~~~
30+
!!! error TS2769: No overload matches this call.
31+
!!! error TS2769: Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
32+
!!! error TS2769: Type 'never[]' is not assignable to type 'number'.
33+
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
34+
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
35+
!!! error TS2769: Target allows only 0 element(s) but source may have more.
36+
!!! related TS6502 /.ts/lib.es5.d.ts:1429:24: The expected type comes from the return type of this signature.
37+
!!! related TS6502 /.ts/lib.es5.d.ts:1435:27: The expected type comes from the return type of this signature.
2038
~~
2139
!!! error TS2769: No overload matches this call.
2240
!!! error TS2769: Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.

tests/baselines/reference/destructuringTuple.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ declare var receiver: typeof tuple;
2323
// Repros from #32140
2424

2525
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
26-
>oops1 : never
27-
>[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : never[]
26+
>oops1 : any
27+
>[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : number
2828
>[1, 2, 3].reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
2929
>[1, 2, 3] : number[]
3030
>1 : 1
3131
>2 : 2
3232
>3 : 3
3333
>reduce : { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; <U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }
34-
>(accu, el) => accu.concat(el) : (accu: never[], el: number) => never[]
35-
>accu : never[]
34+
>(accu, el) => accu.concat(el) : (accu: [], el: number) => never[]
35+
>accu : []
3636
>el : number
3737
>accu.concat(el) : never[]
3838
>accu.concat : { (...items: ConcatArray<never>[]): never[]; (...items: ConcatArray<never>[]): never[]; }
39-
>accu : never[]
39+
>accu : []
4040
>concat : { (...items: ConcatArray<never>[]): never[]; (...items: ConcatArray<never>[]): never[]; }
4141
>el : number
4242
>[] : never[]

tests/cases/fourslash/completionsBindingPatternAffectsInference.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)