mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-21 13:14:43 -06:00
Correctly transform jsdoc parameter types
And give a better name for rest params
This commit is contained in:
parent
724a813105
commit
d797b4ab76
@ -578,10 +578,10 @@ namespace ts {
|
||||
return emitLiteralType(<LiteralTypeNode>node);
|
||||
case SyntaxKind.JSDocAllType:
|
||||
write("*");
|
||||
break;
|
||||
return;
|
||||
case SyntaxKind.JSDocUnknownType:
|
||||
write("?");
|
||||
break;
|
||||
return;
|
||||
case SyntaxKind.JSDocNullableType:
|
||||
return emitJSDocNullableType(node as JSDocNullableType);
|
||||
case SyntaxKind.JSDocNonNullableType:
|
||||
|
||||
@ -189,8 +189,11 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
|
||||
}
|
||||
|
||||
function visitJSDocParameter(node: ParameterDeclaration) {
|
||||
const name = node.name || "arg" + node.parent.parameters.indexOf(node);
|
||||
return createParameter(node.decorators, node.modifiers, node.dotDotDotToken, name, node.questionToken, node.type, node.initializer);
|
||||
const index = node.parent.parameters.indexOf(node);
|
||||
const isRest = node.type.kind === SyntaxKind.JSDocVariadicType && index === node.parent.parameters.length - 1;
|
||||
const name = node.name || (isRest ? "rest" : "arg" + index);
|
||||
const dotdotdot = isRest ? createToken(SyntaxKind.DotDotDotToken) : node.dotDotDotToken;
|
||||
return createParameter(node.decorators, node.modifiers, dotdotdot, name, node.questionToken, visitNode(node.type, transformJSDocType), node.initializer);
|
||||
}
|
||||
|
||||
function visitJSDocTypeReference(node: TypeReferenceNode) {
|
||||
|
||||
9
tests/cases/fourslash/annotateWithTypeFromJSDoc16.ts
Normal file
9
tests/cases/fourslash/annotateWithTypeFromJSDoc16.ts
Normal file
@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @strict: true
|
||||
/////** @type {function(*, ...number, ...boolean): void} */
|
||||
////var /*1*/x;
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/** @type {function(*, ...number, ...boolean): void} */
|
||||
var x: (arg0: any, arg1: number[], ...rest: boolean[]) => void;`, 'Annotate with type from JSDoc', 'annotate');
|
||||
Loading…
x
Reference in New Issue
Block a user