From fa02c808d1f3ba554726aa003793fd5ddef92af0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 7 Mar 2017 09:07:34 -0800 Subject: [PATCH] Remove null and undefined from contextual 'this' type --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 04e1f5911cd..22c294d0243 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11601,7 +11601,7 @@ namespace ts { } } } - if (compilerOptions.noImplicitThis) { + if (noImplicitThis) { const containingLiteral = getContainingObjectLiteral(func); if (containingLiteral) { // We have an object literal method. Check if the containing object literal has a contextual type @@ -11622,9 +11622,9 @@ namespace ts { type = getApparentTypeOfContextualType(literal); } // There was no contextual ThisType for the containing object literal, so the contextual type - // for 'this' is the contextual type for the containing object literal or the type of the object - // literal itself. - return contextualType || checkExpressionCached(containingLiteral); + // for 'this' is the non-null form of the contextual type for the containing object literal or + // the type of the object literal itself. + return contextualType ? getNonNullableType(contextualType) : checkExpressionCached(containingLiteral); } // In an assignment of the form 'obj.xxx = function(...)' or 'obj[xxx] = function(...)', the // contextual type for 'this' is 'obj'.