From d8ee4116ef0a1e2733c8b4888453257e689bcda3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 3 Jan 2019 12:46:39 -0800 Subject: [PATCH 1/2] Fix function declaration without body to be checked as context sensitive Fixes #29032 --- src/compiler/checker.ts | 3 +-- ...TypeArgumentInferenceWithMethodWithoutBody.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 20e6310f771..54f878ebef0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11040,8 +11040,7 @@ namespace ts { function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) { // TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value. - const body = node.body!; - return body.kind === SyntaxKind.Block ? false : isContextSensitive(body); + return !node.body || node.body.kind === SyntaxKind.Block ? false : isContextSensitive(node.body); } function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration { diff --git a/tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts b/tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts new file mode 100644 index 00000000000..82cdd8882e2 --- /dev/null +++ b/tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts @@ -0,0 +1,16 @@ +/// + +////interface ProxyHandler { +//// getPrototypeOf?(target: T): object | null; +////} +////interface ProxyConstructor { +//// new (target: T, handler: ProxyHandler): T; +////} +////declare var Proxy: ProxyConstructor; +////let target = {} +////let proxy = new /**/Proxy(target, { +//// getPrototypeOf() +////}) + +goTo.marker(""); +verify.quickInfoExists(); From f4a6fb79da8eef224ca21046e0cb22d8d44fa012 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 3 Jan 2019 13:29:43 -0800 Subject: [PATCH 2/2] Replace ternary expression --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 54f878ebef0..de44e8bb37c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11040,7 +11040,7 @@ namespace ts { function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) { // TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value. - return !node.body || node.body.kind === SyntaxKind.Block ? false : isContextSensitive(node.body); + return !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body); } function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {