Skip to content

Commit 63cb84f

Browse files
committed
Codefix jsdoc types for anything with a .type
That means type parameters and type arguments are still not handled.
1 parent b082c27 commit 63cb84f

15 files changed

+75
-2
lines changed

src/services/codefixes/fixJSDocTypes.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,27 @@ namespace ts.codefix {
88
function getActionsForJSDocTypes(context: CodeFixContext): CodeAction[] | undefined {
99
const sourceFile = context.sourceFile;
1010
const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
11+
12+
// NOTE: Some locations are not handled yet:
13+
// MappedTypeNode.typeParameters and SignatureDeclaration.typeParameters, as well as CallExpression.typeArguments
1114
const decl = ts.findAncestor(node,
12-
n => n.kind === SyntaxKind.VariableDeclaration ||
15+
n =>
16+
n.kind === SyntaxKind.AsExpression ||
17+
n.kind === SyntaxKind.CallSignature ||
18+
n.kind === SyntaxKind.ConstructSignature ||
19+
n.kind === SyntaxKind.FunctionDeclaration ||
20+
n.kind === SyntaxKind.GetAccessor ||
21+
n.kind === SyntaxKind.IndexSignature ||
22+
n.kind === SyntaxKind.MappedType ||
23+
n.kind === SyntaxKind.MethodDeclaration ||
24+
n.kind === SyntaxKind.MethodSignature ||
1325
n.kind === SyntaxKind.Parameter ||
1426
n.kind === SyntaxKind.PropertyDeclaration ||
15-
n.kind === SyntaxKind.PropertyAssignment);
27+
n.kind === SyntaxKind.PropertySignature ||
28+
n.kind === SyntaxKind.SetAccessor ||
29+
n.kind === SyntaxKind.TypeAliasDeclaration ||
30+
n.kind === SyntaxKind.TypeAssertionExpression ||
31+
n.kind === SyntaxKind.VariableDeclaration);
1632
if (!decl) return;
1733
const checker = context.program.getTypeChecker();
1834

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @strict: true
2+
/// <reference path='fourslash.ts' />
3+
//// var x = 12 as [|number?|];
4+
5+
verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference path='fourslash.ts' />
2+
//// var f = <[|function(number?): number|]>(x => x);
3+
4+
// note: without --strict, number? --> number, not number | null
5+
verify.rangeAfterCodeFix("(arg0: number) => number", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// <reference path='fourslash.ts' />
2+
//// var f: { [K in keyof number]: [|*|] };
3+
4+
verify.rangeAfterCodeFix("any");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path='fourslash.ts' />
2+
//// declare function index(ix: number): [|*|];
3+
verify.rangeAfterCodeFix("any");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path='fourslash.ts' />
2+
//// var index: { (ix: number): [|?|] };
3+
verify.rangeAfterCodeFix("any");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path='fourslash.ts' />
2+
//// var index: { new (ix: number): [|?|] };
3+
verify.rangeAfterCodeFix("any");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path='fourslash.ts' />
2+
//// var index = { get p(): [|*|] { return 12 } };
3+
verify.rangeAfterCodeFix("any");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path='fourslash.ts' />
2+
//// var index = { set p(x: [|*|]) { } };
3+
verify.rangeAfterCodeFix("any");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference path='fourslash.ts' />
2+
//// var index: { [s: string]: [|*|] };
3+
verify.rangeAfterCodeFix("any");

0 commit comments

Comments
 (0)