docs/libs/typescript.js
function getContextualTypeForInitializerExpression(node) {
            var declaration = node.parent;
            if (node === declaration.initializer) {
                if (declaration.type) {
                    return getTypeFromTypeNode(declaration.type);
                }
                if (declaration.kind === 142 /* Parameter */) {
                    var type = getContextuallyTypedParameterType(declaration);
                    if (type) {
                        return type;
                    }
                }
                if (ts.isBindingPattern(declaration.name)) {
                    return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
                }
                if (ts.isBindingPattern(declaration.parent)) {
                    var parentDeclaration = declaration.parent.parent;
                    var name_12 = declaration.propertyName || declaration.name;
                    if (ts.isVariableLike(parentDeclaration) &&
                        parentDeclaration.type &&
                        !ts.isBindingPattern(name_12)) {
                        var text = getTextOfPropertyName(name_12);
                        if (text) {
                            return getTypeOfPropertyOfType(getTypeFromTypeNode(parentDeclaration.type), text);
                        }
                    }
                }
            }
            return undefined;
        }
function getContextualTypeForInitializerExpression(node) {
            var declaration = node.parent;
            if (node === declaration.initializer) {
                if (declaration.type) {
                    return getTypeFromTypeNode(declaration.type);
                }
                if (declaration.kind === 142 /* Parameter */) {
                    var type = getContextuallyTypedParameterType(declaration);
                    if (type) {
                        return type;
                    }
                }
                if (ts.isBindingPattern(declaration.name)) {
                    return getTypeFromBindingPattern(declaration.name, /*includePatternInType*/ true, /*reportErrors*/ false);
                }
                if (ts.isBindingPattern(declaration.parent)) {
                    var parentDeclaration = declaration.parent.parent;
                    var name_12 = declaration.propertyName || declaration.name;
                    if (ts.isVariableLike(parentDeclaration) &&
                        parentDeclaration.type &&
                        !ts.isBindingPattern(name_12)) {
                        var text = getTextOfPropertyName(name_12);
                        if (text) {
                            return getTypeOfPropertyOfType(getTypeFromTypeNode(parentDeclaration.type), text);
                        }
                    }
                }
            }
            return undefined;
        }
function getContextualTypeForInitializerExpression ( node ) { var declaration = node . parent ; if ( node === declaration . initializer ) { if ( declaration . type ) { return getTypeFromTypeNode ( declaration . type ) ; } if ( declaration . kind === 142 /* Parameter */ ) { var type = getContextuallyTypedParameterType ( declaration ) ; if ( type ) { return type ; } } if ( ts . isBindingPattern ( declaration . name ) ) { return getTypeFromBindingPattern ( declaration . name , /*includePatternInType*/ true , /*reportErrors*/ false ) ; } if ( ts . isBindingPattern ( declaration . parent ) ) { var parentDeclaration = declaration . parent . parent ; var name_12 = declaration . propertyName || declaration . name ; if ( ts . isVariableLike ( parentDeclaration ) && parentDeclaration . type && ! ts . isBindingPattern ( name_12 ) ) { var text = getTextOfPropertyName ( name_12 ) ; if ( text ) { return getTypeOfPropertyOfType ( getTypeFromTypeNode ( parentDeclaration . type ) , text ) ; } } } } return undefined ; }
In a variable, parameter or property declaration with a type annotation, the contextual type of an initializer expression is the type of the variable, parameter or property. Otherwise, in a parameter declaration of a contextually typed function expression, the contextual type of an initializer expression is the contextual type of the parameter. Otherwise, in a variable or parameter declaration with a binding pattern name, the contextual type of an initializer expression is the type implied by the binding pattern. Otherwise, in a binding pattern inside a variable or parameter declaration, the contextual type of an initializer expression is the type annotation of the containing declaration, if present.
In a variable parameter or property declaration with a type annotation the contextual type of an initializer expression is the type of the variable parameter or property . Otherwise in a parameter declaration of a contextually typed function expression the contextual type of an initializer expression is the contextual type of the parameter . Otherwise in a variable or parameter declaration with a binding pattern name the contextual type of an initializer expression is the type implied by the binding pattern . Otherwise in a binding pattern inside a variable or parameter declaration the contextual type of an initializer expression is the type annotation of the containing declaration if present .