mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Codefix jsdoc types for anything with a .type
That means type parameters and type arguments are still not handled.
This commit is contained in:
parent
b082c27fbe
commit
63cb84f3d1
@ -8,11 +8,27 @@ namespace ts.codefix {
|
||||
function getActionsForJSDocTypes(context: CodeFixContext): CodeAction[] | undefined {
|
||||
const sourceFile = context.sourceFile;
|
||||
const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false);
|
||||
|
||||
// NOTE: Some locations are not handled yet:
|
||||
// MappedTypeNode.typeParameters and SignatureDeclaration.typeParameters, as well as CallExpression.typeArguments
|
||||
const decl = ts.findAncestor(node,
|
||||
n => n.kind === SyntaxKind.VariableDeclaration ||
|
||||
n =>
|
||||
n.kind === SyntaxKind.AsExpression ||
|
||||
n.kind === SyntaxKind.CallSignature ||
|
||||
n.kind === SyntaxKind.ConstructSignature ||
|
||||
n.kind === SyntaxKind.FunctionDeclaration ||
|
||||
n.kind === SyntaxKind.GetAccessor ||
|
||||
n.kind === SyntaxKind.IndexSignature ||
|
||||
n.kind === SyntaxKind.MappedType ||
|
||||
n.kind === SyntaxKind.MethodDeclaration ||
|
||||
n.kind === SyntaxKind.MethodSignature ||
|
||||
n.kind === SyntaxKind.Parameter ||
|
||||
n.kind === SyntaxKind.PropertyDeclaration ||
|
||||
n.kind === SyntaxKind.PropertyAssignment);
|
||||
n.kind === SyntaxKind.PropertySignature ||
|
||||
n.kind === SyntaxKind.SetAccessor ||
|
||||
n.kind === SyntaxKind.TypeAliasDeclaration ||
|
||||
n.kind === SyntaxKind.TypeAssertionExpression ||
|
||||
n.kind === SyntaxKind.VariableDeclaration);
|
||||
if (!decl) return;
|
||||
const checker = context.program.getTypeChecker();
|
||||
|
||||
|
||||
5
tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts
Normal file
5
tests/cases/fourslash/codeFixChangeJSDocSyntax14.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// @strict: true
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var x = 12 as [|number?|];
|
||||
|
||||
verify.rangeAfterCodeFix("number | null", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);
|
||||
5
tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts
Normal file
5
tests/cases/fourslash/codeFixChangeJSDocSyntax15.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var f = <[|function(number?): number|]>(x => x);
|
||||
|
||||
// note: without --strict, number? --> number, not number | null
|
||||
verify.rangeAfterCodeFix("(arg0: number) => number", /*includeWhiteSpace*/ false, /*errorCode*/ 8020, 0);
|
||||
4
tests/cases/fourslash/codeFixChangeJSDocSyntax16.ts
Normal file
4
tests/cases/fourslash/codeFixChangeJSDocSyntax16.ts
Normal file
@ -0,0 +1,4 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var f: { [K in keyof number]: [|*|] };
|
||||
|
||||
verify.rangeAfterCodeFix("any");
|
||||
3
tests/cases/fourslash/codeFixChangeJSDocSyntax17.ts
Normal file
3
tests/cases/fourslash/codeFixChangeJSDocSyntax17.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// declare function index(ix: number): [|*|];
|
||||
verify.rangeAfterCodeFix("any");
|
||||
3
tests/cases/fourslash/codeFixChangeJSDocSyntax18.ts
Normal file
3
tests/cases/fourslash/codeFixChangeJSDocSyntax18.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var index: { (ix: number): [|?|] };
|
||||
verify.rangeAfterCodeFix("any");
|
||||
3
tests/cases/fourslash/codeFixChangeJSDocSyntax19.ts
Normal file
3
tests/cases/fourslash/codeFixChangeJSDocSyntax19.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var index: { new (ix: number): [|?|] };
|
||||
verify.rangeAfterCodeFix("any");
|
||||
3
tests/cases/fourslash/codeFixChangeJSDocSyntax20.ts
Normal file
3
tests/cases/fourslash/codeFixChangeJSDocSyntax20.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var index = { get p(): [|*|] { return 12 } };
|
||||
verify.rangeAfterCodeFix("any");
|
||||
3
tests/cases/fourslash/codeFixChangeJSDocSyntax21.ts
Normal file
3
tests/cases/fourslash/codeFixChangeJSDocSyntax21.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var index = { set p(x: [|*|]) { } };
|
||||
verify.rangeAfterCodeFix("any");
|
||||
3
tests/cases/fourslash/codeFixChangeJSDocSyntax22.ts
Normal file
3
tests/cases/fourslash/codeFixChangeJSDocSyntax22.ts
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var index: { [s: string]: [|*|] };
|
||||
verify.rangeAfterCodeFix("any");
|
||||
6
tests/cases/fourslash/codeFixChangeJSDocSyntax23.ts
Normal file
6
tests/cases/fourslash/codeFixChangeJSDocSyntax23.ts
Normal file
@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
////class C {
|
||||
//// m(): [|*|] {
|
||||
//// }
|
||||
////}
|
||||
verify.rangeAfterCodeFix("any");
|
||||
5
tests/cases/fourslash/codeFixChangeJSDocSyntax24.ts
Normal file
5
tests/cases/fourslash/codeFixChangeJSDocSyntax24.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
////declare class C {
|
||||
//// m(): [|*|];
|
||||
////}
|
||||
verify.rangeAfterCodeFix("any");
|
||||
5
tests/cases/fourslash/codeFixChangeJSDocSyntax25.ts
Normal file
5
tests/cases/fourslash/codeFixChangeJSDocSyntax25.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
////declare class C {
|
||||
//// p: [|*|];
|
||||
////}
|
||||
verify.rangeAfterCodeFix("any");
|
||||
5
tests/cases/fourslash/codeFixChangeJSDocSyntax26.ts
Normal file
5
tests/cases/fourslash/codeFixChangeJSDocSyntax26.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
////class C {
|
||||
//// p: [|*|] = 12;
|
||||
////}
|
||||
verify.rangeAfterCodeFix("any");
|
||||
4
tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts
Normal file
4
tests/cases/fourslash/codeFixChangeJSDocSyntax27.ts
Normal file
@ -0,0 +1,4 @@
|
||||
// @strict: true
|
||||
/// <reference path='fourslash.ts' />
|
||||
////type T = [|...number?|];
|
||||
verify.rangeAfterCodeFix("(number | null)[]");
|
||||
Loading…
x
Reference in New Issue
Block a user