nl_tokens: Return the inferred type for a variable parameter or property declaration
pl_tokens: function getTypeForVariableLikeDeclaration ( declaration ) { // A variable declared in a for..in statement is always of type any if ( declaration . parent . parent . kind === 200 /* ForInStatement */ ) { return anyType ; } if ( declaration . parent . parent . kind === 201 /* ForOfStatement */ ) { // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like // [Symbol.iterator] or next). This may be because we accessed properties from anyType, // or it may have led to an error inside getElementTypeOfIterable. return checkRightHandSideOfForOf ( declaration . parent . parent . expression ) || anyType ; } if ( ts . isBindingPattern ( declaration . parent ) ) { return getTypeForBindingElement ( declaration ) ; } // Use type from type annotation if one is present if ( declaration . type ) { return getTypeFromTypeNode ( declaration . type ) ; } if ( declaration . kind === 138 /* Parameter */ ) { var func = declaration . parent ; // For a parameter of a set accessor, use the type of the get accessor if one is present if ( func . kind === 146 /* SetAccessor */ && ! ts . hasDynamicName ( func ) ) { var getter = ts . getDeclarationOfKind ( declaration . parent . symbol , 145 /* GetAccessor */ ) ; if ( getter ) { return getReturnTypeOfSignature ( getSignatureFromDeclaration ( getter ) ) ; } } // Use contextual parameter type if one is available var type = getContextuallyTypedParameterType ( declaration ) ; if ( type ) { return type ; } } // Use the type of the initializer expression if one is present if ( declaration . initializer ) { return checkExpressionCached ( declaration . initializer ) ; } // If it is a short-hand property assignment, use the type of the identifier if ( declaration . <mask> === 246 /* ShorthandPropertyAssignment */ ) { return checkIdentifier ( declaration . name ) ; } // If the declaration specifies a binding pattern, use the type implied by the binding pattern if ( ts . isBindingPattern ( declaration . name ) ) { return getTypeFromBindingPattern ( declaration . name , /*includePatternInType*/ false ) ; } // No type specified and nothing can be inferred return undefined ; }