Skip to content

Commit fa02c80

Browse files
committed
Remove null and undefined from contextual 'this' type
1 parent 89f43d1 commit fa02c80

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11601,7 +11601,7 @@ namespace ts {
1160111601
}
1160211602
}
1160311603
}
11604-
if (compilerOptions.noImplicitThis) {
11604+
if (noImplicitThis) {
1160511605
const containingLiteral = getContainingObjectLiteral(func);
1160611606
if (containingLiteral) {
1160711607
// We have an object literal method. Check if the containing object literal has a contextual type
@@ -11622,9 +11622,9 @@ namespace ts {
1162211622
type = getApparentTypeOfContextualType(literal);
1162311623
}
1162411624
// There was no contextual ThisType<T> for the containing object literal, so the contextual type
11625-
// for 'this' is the contextual type for the containing object literal or the type of the object
11626-
// literal itself.
11627-
return contextualType || checkExpressionCached(containingLiteral);
11625+
// for 'this' is the non-null form of the contextual type for the containing object literal or
11626+
// the type of the object literal itself.
11627+
return contextualType ? getNonNullableType(contextualType) : checkExpressionCached(containingLiteral);
1162811628
}
1162911629
// In an assignment of the form 'obj.xxx = function(...)' or 'obj[xxx] = function(...)', the
1163011630
// contextual type for 'this' is 'obj'.

0 commit comments

Comments
 (0)