fix(38868): add separator for type parameters (#39621)

This commit is contained in:
Alexander T
2020-07-16 20:58:16 +03:00
committed by GitHub
parent db79030410
commit 6430211f8f
2 changed files with 33 additions and 1 deletions

View File

@@ -469,7 +469,7 @@ namespace ts.textChanges {
public insertTypeParameters(sourceFile: SourceFile, node: SignatureDeclaration, typeParameters: readonly TypeParameterDeclaration[]): void {
// If no `(`, is an arrow function `x => x`, so use the pos of the first parameter
const start = (findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile) || first(node.parameters)).getStart(sourceFile);
this.insertNodesAt(sourceFile, start, typeParameters, { prefix: "<", suffix: ">" });
this.insertNodesAt(sourceFile, start, typeParameters, { prefix: "<", suffix: ">", joiner: ", " });
}
private getOptionsForInsertNodeBefore(before: Node, inserted: Node, blankLineBetween: boolean): InsertNodeOptions {

View File

@@ -0,0 +1,32 @@
/// <reference path='fourslash.ts' />
// @strict: true
/////**
//// * @typedef Foo
//// * @template L, R
//// */
/////**
//// * @param {function(R): boolean} a
//// * @param {function(R): L} b
//// * @returns {function(R): Foo.<L, R>}
//// * @template L, R
//// */
////function foo(a, b) {
////}
verify.codeFix({
description: ts.Diagnostics.Annotate_with_type_from_JSDoc.message,
index: 2,
newFileContent:
`/**
* @typedef Foo
* @template L, R
*/
/**
* @param {function(R): boolean} a
* @param {function(R): L} b
* @returns {function(R): Foo.<L, R>}
* @template L, R
*/
function foo<L, R>(a: (arg0: R) => boolean, b: (arg0: R) => L): (arg0: R) => Foo<L, R> {
}`,
});