From 7c93affd7dc0efc508362d335d50bf9626808a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Tue, 25 Dec 2018 17:30:04 +0800 Subject: [PATCH] fix typeof completions broken --- src/compiler/checker.ts | 4 ++-- src/compiler/types.ts | 2 +- src/services/completions.ts | 2 +- .../fourslash/completionTypeofExpressions.ts | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/completionTypeofExpressions.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23c5568f2e5..e570b44313e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19263,8 +19263,8 @@ namespace ts { } } - function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol): boolean { - return isValidPropertyAccessWithType(node, node.kind !== SyntaxKind.ImportType && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type) + function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean { + return isValidPropertyAccessWithType(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type) && (!(property.flags & SymbolFlags.Method) || isValidMethodAccess(property, type)); } function isValidMethodAccess(method: Symbol, actualThisType: Type): boolean { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b70b4e4d3d0..0a2ab39ac92 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3108,7 +3108,7 @@ namespace ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName | ImportTypeNode, propertyName: string): boolean; /** Exclude accesses to private properties or methods with a `this` parameter that `type` doesn't satisfy. */ - /* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol): boolean; + /* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean; /** Follow all aliases to get the original symbol. */ getAliasedSymbol(symbol: Symbol): Symbol; /** Follow a *single* alias to get the immediately aliased symbol. */ diff --git a/src/services/completions.ts b/src/services/completions.ts index 43f00c58acf..bbcee4dd47e 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -913,7 +913,7 @@ namespace ts.Completions { } else { for (const symbol of type.getApparentProperties()) { - if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? node : node.parent, type, symbol)) { + if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? node : node.parent, type, symbol)) { addPropertySymbol(symbol); } } diff --git a/tests/cases/fourslash/completionTypeofExpressions.ts b/tests/cases/fourslash/completionTypeofExpressions.ts new file mode 100644 index 00000000000..407fd8d7678 --- /dev/null +++ b/tests/cases/fourslash/completionTypeofExpressions.ts @@ -0,0 +1,15 @@ +/// + +//// const x = "str"; +//// function test(arg: typeof x./*1*/) {} +//// function test1(arg: typeof (x./*2*/)) {} + +verify.completions({ + marker: "1", + includes: ['length'] +}); + +verify.completions({ + marker: "2", + includes: ['length'] +});