mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
@@ -28698,6 +28698,22 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
});
|
||||
}
|
||||
|
||||
function getThisTypeOfObjectLiteralFromContextualType(containingLiteral: ObjectLiteralExpression, contextualType: Type | undefined) {
|
||||
let literal = containingLiteral;
|
||||
let type = contextualType;
|
||||
while (type) {
|
||||
const thisType = getThisTypeFromContextualType(type);
|
||||
if (thisType) {
|
||||
return thisType;
|
||||
}
|
||||
if (literal.parent.kind !== SyntaxKind.PropertyAssignment) {
|
||||
break;
|
||||
}
|
||||
literal = literal.parent.parent as ObjectLiteralExpression;
|
||||
type = getApparentTypeOfContextualType(literal, /*contextFlags*/ undefined);
|
||||
}
|
||||
}
|
||||
|
||||
function getContextualThisParameterType(func: SignatureDeclaration): Type | undefined {
|
||||
if (func.kind === SyntaxKind.ArrowFunction) {
|
||||
return undefined;
|
||||
@@ -28719,18 +28735,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
// that includes a ThisType<T>. If so, T is the contextual type for 'this'. We continue looking in
|
||||
// any directly enclosing object literals.
|
||||
const contextualType = getApparentTypeOfContextualType(containingLiteral, /*contextFlags*/ undefined);
|
||||
let literal = containingLiteral;
|
||||
let type = contextualType;
|
||||
while (type) {
|
||||
const thisType = getThisTypeFromContextualType(type);
|
||||
if (thisType) {
|
||||
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
|
||||
}
|
||||
if (literal.parent.kind !== SyntaxKind.PropertyAssignment) {
|
||||
break;
|
||||
}
|
||||
literal = literal.parent.parent as ObjectLiteralExpression;
|
||||
type = getApparentTypeOfContextualType(literal, /*contextFlags*/ undefined);
|
||||
const thisType = getThisTypeOfObjectLiteralFromContextualType(containingLiteral, contextualType);
|
||||
if (thisType) {
|
||||
return instantiateType(thisType, getMapperFromContext(getInferenceContext(containingLiteral)));
|
||||
}
|
||||
// There was no contextual ThisType<T> for the containing object literal, so the contextual type
|
||||
// for 'this' is the non-null form of the contextual type for the containing object literal or
|
||||
@@ -45455,7 +45462,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
const containingLiteral = getContainingObjectLiteral(container);
|
||||
if (containingLiteral) {
|
||||
const contextualType = getApparentTypeOfContextualType(containingLiteral, /*contextFlags*/ undefined);
|
||||
const type = contextualType && getThisTypeFromContextualType(contextualType);
|
||||
const type = getThisTypeOfObjectLiteralFromContextualType(containingLiteral, contextualType);
|
||||
return type && !isTypeAny(type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user