mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Merge pull request #4862 from Microsoft/contextuallyTypeMethodDeclarations
Contextually type method declaration parameters in object literals
This commit is contained in:
@@ -6574,8 +6574,8 @@ namespace ts {
|
||||
|
||||
// Return contextual type of parameter or undefined if no contextual type is available
|
||||
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
|
||||
if (isFunctionExpressionOrArrowFunction(parameter.parent)) {
|
||||
let func = <FunctionExpression>parameter.parent;
|
||||
let func = parameter.parent;
|
||||
if (isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) {
|
||||
if (isContextSensitive(func)) {
|
||||
let contextualSignature = getContextualSignature(func);
|
||||
if (contextualSignature) {
|
||||
@@ -6907,7 +6907,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isFunctionExpressionOrArrowFunction(node: Node): boolean {
|
||||
function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression {
|
||||
return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction;
|
||||
}
|
||||
|
||||
@@ -6926,8 +6926,8 @@ namespace ts {
|
||||
function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature {
|
||||
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
|
||||
let type = isObjectLiteralMethod(node)
|
||||
? getContextualTypeForObjectLiteralMethod(<MethodDeclaration>node)
|
||||
: getContextualType(<FunctionExpression>node);
|
||||
? getContextualTypeForObjectLiteralMethod(node)
|
||||
: getContextualType(node);
|
||||
if (!type) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -13656,7 +13656,7 @@ namespace ts {
|
||||
forEach(node.decorators, checkFunctionAndClassExpressionBodies);
|
||||
forEach((<MethodDeclaration>node).parameters, checkFunctionAndClassExpressionBodies);
|
||||
if (isObjectLiteralMethod(node)) {
|
||||
checkFunctionExpressionOrObjectLiteralMethodBody(<MethodDeclaration>node);
|
||||
checkFunctionExpressionOrObjectLiteralMethodBody(node);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.Constructor:
|
||||
|
||||
@@ -660,7 +660,7 @@ namespace ts {
|
||||
return node && node.kind === SyntaxKind.Block && isFunctionLike(node.parent);
|
||||
}
|
||||
|
||||
export function isObjectLiteralMethod(node: Node) {
|
||||
export function isObjectLiteralMethod(node: Node): node is MethodDeclaration {
|
||||
return node && node.kind === SyntaxKind.MethodDeclaration && node.parent.kind === SyntaxKind.ObjectLiteralExpression;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user