From ae211983eb7bc88e7e39d432d7be7c0af06955a2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 28 Dec 2017 19:00:54 -0800 Subject: [PATCH] Add method signature handler to getTypeOfVariableOrParameterOrProperty (#20825) --- src/compiler/checker.ts | 3 ++- ...odSignatureHandledDeclarationKindForSymbol.js | 12 ++++++++++++ ...natureHandledDeclarationKindForSymbol.symbols | 16 ++++++++++++++++ ...ignatureHandledDeclarationKindForSymbol.types | 16 ++++++++++++++++ ...odSignatureHandledDeclarationKindForSymbol.ts | 8 ++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.js create mode 100644 tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols create mode 100644 tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types create mode 100644 tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 82ab87d3160..3f5d2cf68fe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4683,7 +4683,8 @@ namespace ts { else if (isJSDocPropertyTag(declaration) || isPropertyAccessExpression(declaration) || isIdentifier(declaration) - || isMethodDeclaration(declaration) && !isObjectLiteralMethod(declaration)) { + || (isMethodDeclaration(declaration) && !isObjectLiteralMethod(declaration)) + || isMethodSignature(declaration)) { // TODO: Mimics old behavior from incorrect usage of getWidenedTypeForVariableLikeDeclaration, but seems incorrect type = tryGetTypeFromEffectiveTypeNode(declaration) || anyType; } diff --git a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.js b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.js new file mode 100644 index 00000000000..f4f46b92c3e --- /dev/null +++ b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.js @@ -0,0 +1,12 @@ +//// [methodSignatureHandledDeclarationKindForSymbol.ts] +interface Foo { + bold(): string; +} + +interface Foo { + bold: string; +} + + + +//// [methodSignatureHandledDeclarationKindForSymbol.js] diff --git a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols new file mode 100644 index 00000000000..27bc633ce57 --- /dev/null +++ b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 0), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 2, 1)) + + bold(): string; +>bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 15), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 4, 15)) +} + +interface Foo { +>Foo : Symbol(Foo, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 0), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 2, 1)) + + bold: string; +>bold : Symbol(Foo.bold, Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 0, 15), Decl(methodSignatureHandledDeclarationKindForSymbol.ts, 4, 15)) +} + + diff --git a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types new file mode 100644 index 00000000000..6f01b381f45 --- /dev/null +++ b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts === +interface Foo { +>Foo : Foo + + bold(): string; +>bold : string +} + +interface Foo { +>Foo : Foo + + bold: string; +>bold : string +} + + diff --git a/tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts b/tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts new file mode 100644 index 00000000000..f92927da4e3 --- /dev/null +++ b/tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts @@ -0,0 +1,8 @@ +interface Foo { + bold(): string; +} + +interface Foo { + bold: string; +} +