Stop looking at binding patterns for type argument inference (#45719)
* Ignore empty binding patterns for contextual typing * Stop looking at binding patterns for type argument inference entirely
This commit is contained in:
parent
bac841ef18
commit
be618b1446
|
@ -25314,7 +25314,8 @@ namespace ts {
|
|||
if (result) {
|
||||
return result;
|
||||
}
|
||||
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
|
||||
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
|
||||
return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
|
||||
}
|
||||
}
|
||||
|
@ -28613,7 +28614,7 @@ namespace ts {
|
|||
// 'let f: (x: string) => number = wrap(s => s.length)', we infer from the declared type of 'f' to the
|
||||
// return type of 'wrap'.
|
||||
if (node.kind !== SyntaxKind.Decorator) {
|
||||
const contextualType = getContextualType(node, every(signature.typeParameters, p => !!getDefaultFromTypeParameter(p)) ? ContextFlags.SkipBindingPatterns : ContextFlags.None);
|
||||
const contextualType = getContextualType(node, ContextFlags.SkipBindingPatterns);
|
||||
if (contextualType) {
|
||||
// We clone the inference context to avoid disturbing a resolution in progress for an
|
||||
// outer call expression. Effectively we just want a snapshot of whatever has been
|
||||
|
|
|
@ -1,10 +1,3 @@
|
|||
tests/cases/compiler/destructuringTuple.ts(11,7): error TS2461: Type 'number' is not an array type.
|
||||
tests/cases/compiler/destructuringTuple.ts(11,48): error TS2769: No overload matches this call.
|
||||
Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
|
||||
Type 'never[]' is not assignable to type 'number'.
|
||||
Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
|
||||
Type 'never[]' is not assignable to type '[]'.
|
||||
Target allows only 0 element(s) but source may have more.
|
||||
tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload matches this call.
|
||||
Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
|
||||
Argument of type 'number' is not assignable to parameter of type 'ConcatArray<never>'.
|
||||
|
@ -12,7 +5,7 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat
|
|||
Argument of type 'number' is not assignable to parameter of type 'ConcatArray<never>'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/destructuringTuple.ts (3 errors) ====
|
||||
==== tests/cases/compiler/destructuringTuple.ts (1 errors) ====
|
||||
declare var tuple: [boolean, number, ...string[]];
|
||||
|
||||
const [a, b, c, ...rest] = tuple;
|
||||
|
@ -24,17 +17,6 @@ tests/cases/compiler/destructuringTuple.ts(11,60): error TS2769: No overload mat
|
|||
// Repros from #32140
|
||||
|
||||
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
|
||||
~~~~~~~
|
||||
!!! error TS2461: Type 'number' is not an array type.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2769: No overload matches this call.
|
||||
!!! error TS2769: Overload 1 of 3, '(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number', gave the following error.
|
||||
!!! error TS2769: Type 'never[]' is not assignable to type 'number'.
|
||||
!!! error TS2769: Overload 2 of 3, '(callbackfn: (previousValue: [], currentValue: number, currentIndex: number, array: number[]) => [], initialValue: []): []', gave the following error.
|
||||
!!! error TS2769: Type 'never[]' is not assignable to type '[]'.
|
||||
!!! error TS2769: Target allows only 0 element(s) but source may have more.
|
||||
!!! related TS6502 /.ts/lib.es5.d.ts:1412:24: The expected type comes from the return type of this signature.
|
||||
!!! related TS6502 /.ts/lib.es5.d.ts:1418:27: The expected type comes from the return type of this signature.
|
||||
~~
|
||||
!!! error TS2769: No overload matches this call.
|
||||
!!! error TS2769: Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
|
||||
|
|
|
@ -23,20 +23,20 @@ declare var receiver: typeof tuple;
|
|||
// Repros from #32140
|
||||
|
||||
const [oops1] = [1, 2, 3].reduce((accu, el) => accu.concat(el), []);
|
||||
>oops1 : any
|
||||
>[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : number
|
||||
>oops1 : never
|
||||
>[1, 2, 3].reduce((accu, el) => accu.concat(el), []) : never[]
|
||||
>[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; }
|
||||
>[1, 2, 3] : number[]
|
||||
>1 : 1
|
||||
>2 : 2
|
||||
>3 : 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; }
|
||||
>(accu, el) => accu.concat(el) : (accu: [], el: number) => never[]
|
||||
>accu : []
|
||||
>(accu, el) => accu.concat(el) : (accu: never[], el: number) => never[]
|
||||
>accu : never[]
|
||||
>el : number
|
||||
>accu.concat(el) : never[]
|
||||
>accu.concat : { (...items: ConcatArray<never>[]): never[]; (...items: ConcatArray<never>[]): never[]; }
|
||||
>accu : []
|
||||
>accu : never[]
|
||||
>concat : { (...items: ConcatArray<never>[]): never[]; (...items: ConcatArray<never>[]): never[]; }
|
||||
>el : number
|
||||
>[] : never[]
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// declare function pick<T, K extends keyof T>(keys: K[], obj: T): Pick<T, K>;
|
||||
//// const { /**/ } = pick(['b'], { a: 'a', b: 'b' });
|
||||
|
||||
verify.completions({
|
||||
marker: "",
|
||||
exact: ["b"]
|
||||
});
|
Loading…
Reference in a new issue