Skip to content

Commit 806a710

Browse files
authored
fix(49478): add return type to method signature (microsoft#49482)
1 parent e6808c4 commit 806a710

File tree

6 files changed

+43
-4
lines changed

6 files changed

+43
-4
lines changed

src/services/codefixes/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ namespace ts.codefix {
332332
/*questionToken*/ undefined,
333333
typeParameters,
334334
parameters,
335-
type
335+
type === undefined ? factory.createKeywordTypeNode(SyntaxKind.UnknownKeyword) : type
336336
);
337337
case SyntaxKind.FunctionDeclaration:
338338
return factory.createFunctionDeclaration(

src/services/textChanges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ namespace ts.textChanges {
682682
return {
683683
indentation,
684684
prefix: (insertLeadingComma ? "," : "") + this.newLineCharacter,
685-
suffix: insertTrailingComma ? "," : ""
685+
suffix: insertTrailingComma ? "," : isInterfaceDeclaration(node) && isEmpty ? ";" : ""
686686
};
687687
}
688688

tests/cases/fourslash/codeFixAddMissingMember24.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ verify.codeFix({
1010
index: 0,
1111
newRangeContent:
1212
`type Foo = {
13-
test(arg0: number, arg1: number, arg2: string);
13+
test(arg0: number, arg1: number, arg2: string): unknown;
1414
};`
1515
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitAny: true
4+
5+
////interface IFoo {}
6+
////const foo: IFoo = {}
7+
////foo.bar()
8+
9+
verify.codeFix({
10+
description: [ts.Diagnostics.Declare_method_0.message, "bar"],
11+
index: 0,
12+
newFileContent:
13+
`interface IFoo {
14+
bar(): unknown;
15+
}
16+
const foo: IFoo = {}
17+
foo.bar()`,
18+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitAny: true
4+
5+
////interface IFoo {
6+
//// b(): void;
7+
////}
8+
////const foo: IFoo = {}
9+
////foo.a()
10+
11+
verify.codeFix({
12+
description: [ts.Diagnostics.Declare_method_0.message, "a"],
13+
index: 1,
14+
newFileContent:
15+
`interface IFoo {
16+
a(): unknown;
17+
b(): void;
18+
}
19+
const foo: IFoo = {}
20+
foo.a()`,
21+
});

tests/cases/fourslash/codeFixAddMissingMember_all.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ En.A;
7272
type T = {
7373
x: any;
7474
y: number;
75-
test(arg0: number, arg1: number);
75+
test(arg0: number, arg1: number): unknown;
7676
};
7777
function foo(t: T) {
7878
t.x;

0 commit comments

Comments
 (0)