Contextually type this in getDeclFromSig, not checkThisExpr

This commit is contained in:
Nathan Shively-Sanders 2016-08-22 14:08:34 -07:00
Родитель 0f483d6546
Коммит 5aafc2c848
1 изменённых файлов: 13 добавлений и 9 удалений

Просмотреть файл

@ -3063,9 +3063,14 @@ namespace ts {
}
}
// Use contextual parameter type if one is available
const type = declaration.symbol.name === "this"
? getContextuallyTypedThisType(func)
: getContextuallyTypedParameterType(<ParameterDeclaration>declaration);
let type: Type;
if (declaration.symbol.name === "this") {
const thisParameter = getContextuallyTypedThisParameter(func);
type = thisParameter ? getTypeOfSymbol(thisParameter) : undefined;
}
else {
type = getContextuallyTypedParameterType(<ParameterDeclaration>declaration);
}
if (type) {
return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality);
}
@ -4689,6 +4694,9 @@ namespace ts {
if (isJSConstructSignature) {
minArgumentCount--;
}
if (!thisParameter && isObjectLiteralMethod(declaration)) {
thisParameter = getContextuallyTypedThisParameter(declaration);
}
const classType = declaration.kind === SyntaxKind.Constructor ?
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol))
@ -9087,10 +9095,6 @@ namespace ts {
if (thisType) {
return thisType;
}
const type = getContextuallyTypedThisType(container);
if (type) {
return type;
}
}
if (isClassLike(container.parent)) {
const symbol = getSymbolOfNode(container.parent);
@ -9326,11 +9330,11 @@ namespace ts {
}
}
function getContextuallyTypedThisType(func: FunctionLikeDeclaration): Type {
function getContextuallyTypedThisParameter(func: FunctionLikeDeclaration): Symbol {
if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== SyntaxKind.ArrowFunction) {
const contextualSignature = getContextualSignature(func);
if (contextualSignature) {
return getThisTypeOfSignature(contextualSignature);
return contextualSignature.thisParameter;
}
}