Skip to content

Commit ae21198

Browse files
authored
Add method signature handler to getTypeOfVariableOrParameterOrProperty (microsoft#20825)
1 parent 196f1c2 commit ae21198

5 files changed

Lines changed: 54 additions & 1 deletion

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4683,7 +4683,8 @@ namespace ts {
46834683
else if (isJSDocPropertyTag(declaration)
46844684
|| isPropertyAccessExpression(declaration)
46854685
|| isIdentifier(declaration)
4686-
|| isMethodDeclaration(declaration) && !isObjectLiteralMethod(declaration)) {
4686+
|| (isMethodDeclaration(declaration) && !isObjectLiteralMethod(declaration))
4687+
|| isMethodSignature(declaration)) {
46874688
// TODO: Mimics old behavior from incorrect usage of getWidenedTypeForVariableLikeDeclaration, but seems incorrect
46884689
type = tryGetTypeFromEffectiveTypeNode(declaration) || anyType;
46894690
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [methodSignatureHandledDeclarationKindForSymbol.ts]
2+
interface Foo {
3+
bold(): string;
4+
}
5+
6+
interface Foo {
7+
bold: string;
8+
}
9+
10+
11+
12+
//// [methodSignatureHandledDeclarationKindForSymbol.js]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts ===
2+
interface Foo {
3+
>Foo : Symbol(Foo, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 0), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 2, 1))
4+
5+
bold(): string;
6+
>bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 15), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 4, 15))
7+
}
8+
9+
interface Foo {
10+
>Foo : Symbol(Foo, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 0), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 2, 1))
11+
12+
bold: string;
13+
>bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 15), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 4, 15))
14+
}
15+
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts ===
2+
interface Foo {
3+
>Foo : Foo
4+
5+
bold(): string;
6+
>bold : string
7+
}
8+
9+
interface Foo {
10+
>Foo : Foo
11+
12+
bold: string;
13+
>bold : string
14+
}
15+
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface Foo {
2+
bold(): string;
3+
}
4+
5+
interface Foo {
6+
bold: string;
7+
}
8+

0 commit comments

Comments
 (0)