Codefix for Array.<number> -> Array<number>

This commit is contained in:
Nathan Shively-Sanders 2017-07-17 10:33:04 -07:00
parent dba552d071
commit 3776b0b58b
3 changed files with 11 additions and 6 deletions

View file

@ -7,13 +7,14 @@ namespace ts.codefix {
function getActionsForJSDocTypes(context: CodeFixContext): CodeAction[] | undefined {
const sourceFile = context.sourceFile;
const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
if (node.kind !== SyntaxKind.VariableDeclaration) return;
const decl = ts.findAncestor(node, n => n.kind === SyntaxKind.VariableDeclaration);
if (!decl) return;
const jsdocType = (decl as VariableDeclaration).type;
// TODO: Only if get(jsdoctype) !== jsdoctype
const trk = textChanges.ChangeTracker.fromCodeFixContext(context);
const jsdocType = (node as VariableDeclaration).type;
// TODO: Only if get(jsdoctype) !== jsdoctype
trk.replaceNode(sourceFile, jsdocType, getTypeFromJSDocType(jsdocType));
return [{
// TODO: This seems like the LEAST SAFE way to get the new text

View file

@ -1,4 +1,4 @@
/// <reference path='fourslash.ts' />
//// var x: [|...number|] = 12;
//// var x: [|......number[][]|] = 12;
verify.rangeAfterCodeFix("number[]");
verify.rangeAfterCodeFix("number[][][][]");

View file

@ -0,0 +1,4 @@
/// <reference path='fourslash.ts' />
//// var x: [|Array.<number>|] = 12;
verify.rangeAfterCodeFix("Array<number>");