From 21ab39649c0a090ef7bc1e7dfd701b5254947b61 Mon Sep 17 00:00:00 2001 From: Joseph Wunderlich Date: Fri, 22 Feb 2019 17:24:21 -0800 Subject: [PATCH] remove any annotation from declare method quickfix --- src/services/codefixes/helpers.ts | 2 +- .../fourslash/codeFixAddMissingMember9.ts | 2 +- .../fourslash/codeFixAddMissingMember_all.ts | 2 +- ...eFixAddMissingMember_generator_function.ts | 2 +- ...AddMissingMember_non_generator_function.ts | 2 +- .../codeFixUndeclaredAcrossFiles1.ts | 6 ++-- .../codeFixUndeclaredAcrossFiles3.ts | 2 +- .../codeFixUndeclaredInStaticMethod.ts | 14 ++++---- .../fourslash/codeFixUndeclaredMethod.ts | 12 +++---- .../codeFixUndeclaredMethodFunctionArgs.ts | 6 ++-- ...odeFixUndeclaredMethodObjectLiteralArgs.ts | 35 ++++++++++++++++++- 11 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index ec86415b9fa..5f448653a78 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -156,7 +156,7 @@ namespace ts.codefix { isIdentifier(arg) ? arg.text : isPropertyAccessExpression(arg) ? arg.name.text : undefined); const contextualType = checker.getContextualType(call); - const returnType = inJs ? undefined : contextualType && checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker) || createKeywordTypeNode(SyntaxKind.AnyKeyword); + const returnType = inJs ? undefined : contextualType && checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker); return createMethod( /*decorators*/ undefined, /*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, diff --git a/tests/cases/fourslash/codeFixAddMissingMember9.ts b/tests/cases/fourslash/codeFixAddMissingMember9.ts index b583cd28e9a..e22e854c2e5 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember9.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember9.ts @@ -18,7 +18,7 @@ verify.codeFixAll({ const x = 0; this.y(x, "a", this.z); } - y(x: number, arg1: string, z: boolean): any { + y(x: number, arg1: string, z: boolean) { throw new Error("Method not implemented."); } }`, diff --git a/tests/cases/fourslash/codeFixAddMissingMember_all.ts b/tests/cases/fourslash/codeFixAddMissingMember_all.ts index 6c7076dd341..9c0c86f282d 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember_all.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember_all.ts @@ -36,7 +36,7 @@ verify.codeFixAll({ this.y(); this.x = ""; } - y(): any { + y() { throw new Error("Method not implemented."); } } diff --git a/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts b/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts index 6742cc43348..ad0bd7b47ca 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember_generator_function.ts @@ -14,7 +14,7 @@ verify.codeFixAll({ *method() { yield* this.y(); } - *y(): any { + *y() { throw new Error("Method not implemented."); } }`, diff --git a/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts b/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts index a868646446a..c3773bf285c 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember_non_generator_function.ts @@ -14,7 +14,7 @@ verify.codeFixAll({ method() { yield* this.y(); } - y(): any { + y() { throw new Error("Method not implemented."); } }`, diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts index 8f775d5158e..a8171668751 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts @@ -23,15 +23,15 @@ verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); verify.rangeIs(` - m2(c: C): any { + m2(c: C) { throw new Error("Method not implemented."); } y: {}; - m1(): any { + m1() { throw new Error("Method not implemented."); } static x: any; - static m0(arg0: number, arg1: string, arg2: undefined[]): any { + static m0(arg0: number, arg1: string, arg2: undefined[]) { throw new Error("Method not implemented."); } `); diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts index dcf5c999d6a..9ea5ac1a165 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts @@ -20,7 +20,7 @@ verify.getAndApplyCodeFix(/*errorCode*/ undefined, 0); verify.rangeIs(` - m0(arg0: import("./f2").D): any { + m0(arg0: import("./f2").D) { throw new Error("Method not implemented."); } `); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts index a406360c500..17fcd9ce688 100644 --- a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts @@ -20,7 +20,7 @@ verify.codeFix({ this.prop1 = 10; A.prop2 = "asdf"; } - static m1(arg0: number, arg1: number, arg2: number): any { + static m1(arg0: number, arg1: number, arg2: number) { throw new Error("Method not implemented."); } }`, @@ -38,10 +38,10 @@ verify.codeFix({ this.prop1 = 10; A.prop2 = "asdf"; } - static m2(arg0: number, arg1: number): any { + static m2(arg0: number, arg1: number) { throw new Error("Method not implemented."); } - static m1(arg0: number, arg1: number, arg2: number): any { + static m1(arg0: number, arg1: number, arg2: number) { throw new Error("Method not implemented."); } }`, @@ -60,10 +60,10 @@ verify.codeFix({ this.prop1 = 10; A.prop2 = "asdf"; } - static m2(arg0: number, arg1: number): any { + static m2(arg0: number, arg1: number) { throw new Error("Method not implemented."); } - static m1(arg0: number, arg1: number, arg2: number): any { + static m1(arg0: number, arg1: number, arg2: number) { throw new Error("Method not implemented."); } }`, @@ -83,10 +83,10 @@ verify.codeFix({ this.prop1 = 10; A.prop2 = "asdf"; } - static m2(arg0: number, arg1: number): any { + static m2(arg0: number, arg1: number) { throw new Error("Method not implemented."); } - static m1(arg0: number, arg1: number, arg2: number): any { + static m1(arg0: number, arg1: number, arg2: number) { throw new Error("Method not implemented."); } }`, diff --git a/tests/cases/fourslash/codeFixUndeclaredMethod.ts b/tests/cases/fourslash/codeFixUndeclaredMethod.ts index 151192078f3..32713e5dd19 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethod.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethod.ts @@ -15,7 +15,7 @@ verify.codeFix({ index: 0, newFileContent: `class A { - foo1(arg0: number, arg1: number, arg2: number): any { + foo1(arg0: number, arg1: number, arg2: number) { throw new Error("Method not implemented."); } constructor() { @@ -34,10 +34,10 @@ verify.codeFix({ index: 0, newFileContent: `class A { - foo2(): any { + foo2() { throw new Error("Method not implemented."); } - foo1(arg0: number, arg1: number, arg2: number): any { + foo1(arg0: number, arg1: number, arg2: number) { throw new Error("Method not implemented."); } constructor() { @@ -56,13 +56,13 @@ verify.codeFix({ index: 0, newFileContent: `class A { - foo3(): any { + foo3() { throw new Error("Method not implemented."); } - foo2(): any { + foo2() { throw new Error("Method not implemented."); } - foo1(arg0: number, arg1: number, arg2: number): any { + foo1(arg0: number, arg1: number, arg2: number) { throw new Error("Method not implemented."); } constructor() { diff --git a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs.ts b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs.ts index 478b2a7c647..c4056625b70 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs.ts @@ -11,7 +11,7 @@ verify.codeFix({ description: "Declare method 'foo1'", index: 0, newRangeContent: ` - foo1(arg0: () => number, arg1: () => string, arg2: () => boolean): any { + foo1(arg0: () => number, arg1: () => string, arg2: () => boolean) { throw new Error("Method not implemented."); } `, @@ -22,10 +22,10 @@ verify.codeFix({ description: "Declare method 'foo2'", index: 0, newRangeContent: ` - foo2(arg0: (a: number) => number, arg1: (b: string) => string, arg2: (c: boolean) => boolean): any { + foo2(arg0: (a: number) => number, arg1: (b: string) => string, arg2: (c: boolean) => boolean) { throw new Error("Method not implemented."); } - foo1(arg0: () => number, arg1: () => string, arg2: () => boolean): any { + foo1(arg0: () => number, arg1: () => string, arg2: () => boolean) { throw new Error("Method not implemented."); } `, diff --git a/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts b/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts index bd434cf9d9d..5c0698ad653 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethodObjectLiteralArgs.ts @@ -3,6 +3,8 @@ //// class A {[| //// |]constructor() { //// this.foo1(null, {}, { a: 1, b: "2"}); +//// const bar = this.foo2(null, {}, { a: 1, b: "2"}); +//// const baz: number = this.foo3(null, {}, { a: 1, b: "2"}); //// } //// } @@ -10,7 +12,38 @@ verify.codeFix({ description: "Declare method 'foo1'", index: 0, newRangeContent: ` - foo1(arg0: null, arg1: {}, arg2: { a: number; b: string; }): any { + foo1(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + throw new Error("Method not implemented."); + } + `, + applyChanges: true +}); + +verify.codeFix({ + description: "Declare method 'foo2'", + index: 0, + newRangeContent: ` + foo2(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + throw new Error("Method not implemented."); + } + foo1(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + throw new Error("Method not implemented."); + } + `, + applyChanges: true +}); + +verify.codeFix({ + description: "Declare method 'foo3'", + index: 0, + newRangeContent: ` + foo3(arg0: null, arg1: {}, arg2: { a: number; b: string; }): number { + throw new Error("Method not implemented."); + } + foo2(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { + throw new Error("Method not implemented."); + } + foo1(arg0: null, arg1: {}, arg2: { a: number; b: string; }) { throw new Error("Method not implemented."); } `