mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Merge pull request #30292 from Microsoft/fixRestSignatureRelation
Fix relation of signatures with rest parameter
This commit is contained in:
commit
281eeac249
@ -21773,9 +21773,14 @@ namespace ts {
|
||||
return getTypeOfParameter(signature.parameters[pos]);
|
||||
}
|
||||
if (signature.hasRestParameter) {
|
||||
// We want to return the value undefined for an out of bounds parameter position,
|
||||
// so we need to check bounds here before calling getIndexedAccessType (which
|
||||
// otherwise would return the type 'undefined').
|
||||
const restType = getTypeOfSymbol(signature.parameters[paramCount]);
|
||||
const indexType = getLiteralType(pos - paramCount);
|
||||
return getIndexedAccessType(restType, indexType);
|
||||
const index = pos - paramCount;
|
||||
if (!isTupleType(restType) || restType.target.hasRestElement || index < (restType.typeArguments || emptyArray).length) {
|
||||
return getIndexedAccessType(restType, getLiteralType(index));
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
tests/cases/compiler/getParameterNameAtPosition.ts(9,7): error TS2345: Argument of type 'Mock<[any]>' is not assignable to parameter of type 'Tester'.
|
||||
Types of parameters 'args_1' and 'done' are incompatible.
|
||||
Type '(...args: any[]) => any' is not assignable to type 'undefined'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/getParameterNameAtPosition.ts (1 errors) ====
|
||||
// Repro from #30171
|
||||
|
||||
interface Mock<Y extends any[]> extends Function {
|
||||
(...args: Y): any;
|
||||
}
|
||||
type Tester = (opts: any, done: (...args: any[]) => any) => any;
|
||||
declare function cases(tester: Tester): void;
|
||||
declare function fn<Y extends any[]>(implementation?: (...args: Y) => any): Mock<Y>;
|
||||
cases(fn(opts => { }));
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type 'Mock<[any]>' is not assignable to parameter of type 'Tester'.
|
||||
!!! error TS2345: Types of parameters 'args_1' and 'done' are incompatible.
|
||||
!!! error TS2345: Type '(...args: any[]) => any' is not assignable to type 'undefined'.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user