diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9b59cb3574d18..179e5fb04d08e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21641,7 +21641,7 @@ namespace ts { if (isTupleType(restType)) { const associatedNames = ((restType).target).associatedNames; const index = pos - paramCount; - return associatedNames ? associatedNames[index] : restParameter.escapedName + "_" + index as __String; + return associatedNames && associatedNames[index] || restParameter.escapedName + "_" + index as __String; } return restParameter.escapedName; } diff --git a/tests/baselines/reference/getParameterNameAtPosition.errors.txt b/tests/baselines/reference/getParameterNameAtPosition.errors.txt new file mode 100644 index 0000000000000..74a31fd3def13 --- /dev/null +++ b/tests/baselines/reference/getParameterNameAtPosition.errors.txt @@ -0,0 +1,20 @@ +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 extends Function { + (...args: Y): any; + } + type Tester = (opts: any, done: (...args: any[]) => any) => any; + declare function cases(tester: Tester): void; + declare function fn(implementation?: (...args: Y) => any): Mock; + 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'. + \ No newline at end of file diff --git a/tests/baselines/reference/getParameterNameAtPosition.js b/tests/baselines/reference/getParameterNameAtPosition.js new file mode 100644 index 0000000000000..fed4aebad6e0f --- /dev/null +++ b/tests/baselines/reference/getParameterNameAtPosition.js @@ -0,0 +1,16 @@ +//// [getParameterNameAtPosition.ts] +// Repro from #30171 + +interface Mock extends Function { + (...args: Y): any; +} +type Tester = (opts: any, done: (...args: any[]) => any) => any; +declare function cases(tester: Tester): void; +declare function fn(implementation?: (...args: Y) => any): Mock; +cases(fn(opts => { })); + + +//// [getParameterNameAtPosition.js] +"use strict"; +// Repro from #30171 +cases(fn(function (opts) { })); diff --git a/tests/baselines/reference/getParameterNameAtPosition.symbols b/tests/baselines/reference/getParameterNameAtPosition.symbols new file mode 100644 index 0000000000000..d8148a3733b31 --- /dev/null +++ b/tests/baselines/reference/getParameterNameAtPosition.symbols @@ -0,0 +1,37 @@ +=== tests/cases/compiler/getParameterNameAtPosition.ts === +// Repro from #30171 + +interface Mock extends Function { +>Mock : Symbol(Mock, Decl(getParameterNameAtPosition.ts, 0, 0)) +>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 2, 15)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + (...args: Y): any; +>args : Symbol(args, Decl(getParameterNameAtPosition.ts, 3, 5)) +>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 2, 15)) +} +type Tester = (opts: any, done: (...args: any[]) => any) => any; +>Tester : Symbol(Tester, Decl(getParameterNameAtPosition.ts, 4, 1)) +>opts : Symbol(opts, Decl(getParameterNameAtPosition.ts, 5, 15)) +>done : Symbol(done, Decl(getParameterNameAtPosition.ts, 5, 25)) +>args : Symbol(args, Decl(getParameterNameAtPosition.ts, 5, 33)) + +declare function cases(tester: Tester): void; +>cases : Symbol(cases, Decl(getParameterNameAtPosition.ts, 5, 64)) +>tester : Symbol(tester, Decl(getParameterNameAtPosition.ts, 6, 23)) +>Tester : Symbol(Tester, Decl(getParameterNameAtPosition.ts, 4, 1)) + +declare function fn(implementation?: (...args: Y) => any): Mock; +>fn : Symbol(fn, Decl(getParameterNameAtPosition.ts, 6, 45)) +>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 7, 20)) +>implementation : Symbol(implementation, Decl(getParameterNameAtPosition.ts, 7, 37)) +>args : Symbol(args, Decl(getParameterNameAtPosition.ts, 7, 55)) +>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 7, 20)) +>Mock : Symbol(Mock, Decl(getParameterNameAtPosition.ts, 0, 0)) +>Y : Symbol(Y, Decl(getParameterNameAtPosition.ts, 7, 20)) + +cases(fn(opts => { })); +>cases : Symbol(cases, Decl(getParameterNameAtPosition.ts, 5, 64)) +>fn : Symbol(fn, Decl(getParameterNameAtPosition.ts, 6, 45)) +>opts : Symbol(opts, Decl(getParameterNameAtPosition.ts, 8, 9)) + diff --git a/tests/baselines/reference/getParameterNameAtPosition.types b/tests/baselines/reference/getParameterNameAtPosition.types new file mode 100644 index 0000000000000..f722d7e5f9533 --- /dev/null +++ b/tests/baselines/reference/getParameterNameAtPosition.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/getParameterNameAtPosition.ts === +// Repro from #30171 + +interface Mock extends Function { + (...args: Y): any; +>args : Y +} +type Tester = (opts: any, done: (...args: any[]) => any) => any; +>Tester : Tester +>opts : any +>done : (...args: any[]) => any +>args : any[] + +declare function cases(tester: Tester): void; +>cases : (tester: Tester) => void +>tester : Tester + +declare function fn(implementation?: (...args: Y) => any): Mock; +>fn : (implementation?: ((...args: Y) => any) | undefined) => Mock +>implementation : ((...args: Y) => any) | undefined +>args : Y + +cases(fn(opts => { })); +>cases(fn(opts => { })) : void +>cases : (tester: Tester) => void +>fn(opts => { }) : Mock<[any]> +>fn : (implementation?: ((...args: Y) => any) | undefined) => Mock +>opts => { } : (opts: any) => void +>opts : any + diff --git a/tests/cases/compiler/getParameterNameAtPosition.ts b/tests/cases/compiler/getParameterNameAtPosition.ts new file mode 100644 index 0000000000000..e7a6dc4082766 --- /dev/null +++ b/tests/cases/compiler/getParameterNameAtPosition.ts @@ -0,0 +1,11 @@ +// @strict: true + +// Repro from #30171 + +interface Mock extends Function { + (...args: Y): any; +} +type Tester = (opts: any, done: (...args: any[]) => any) => any; +declare function cases(tester: Tester): void; +declare function fn(implementation?: (...args: Y) => any): Mock; +cases(fn(opts => { }));