code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function typeRelatedToSomeType(source, target, reportErrors) { var targetTypes = target.types; for (var i = 0, len = targetTypes.length; i < len; i++) { var related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1); if (related) { return related; } } return 0 /* False */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
typeRelatedToSomeType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function typeRelatedToEachType(source, target, reportErrors) { var result = -1 /* True */; var targetTypes = target.types; for (var _i = 0, targetTypes_1 = targetTypes; _i < targetTypes_1.length; _i++) { var targetType = targetTypes_1[_i]; var related = isRelatedTo(source, targetType, reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
typeRelatedToEachType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function someTypeRelatedToType(source, target, reportErrors) { var sourceTypes = source.types; for (var i = 0, len = sourceTypes.length; i < len; i++) { var related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1); if (related) { return related; } } return 0 /* False */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
someTypeRelatedToType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function eachTypeRelatedToType(source, target, reportErrors) { var result = -1 /* True */; var sourceTypes = source.types; for (var _i = 0, sourceTypes_2 = sourceTypes; _i < sourceTypes_2.length; _i++) { var sourceType = sourceTypes_2[_i]; var related = isRelatedTo(sourceType, target, reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
eachTypeRelatedToType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function typeArgumentsRelatedTo(source, target, reportErrors) { var sources = source.typeArguments || emptyArray; var targets = target.typeArguments || emptyArray; if (sources.length !== targets.length && relation === identityRelation) { return 0 /* False */; } var result = -1 /* True */; for (var i = 0; i < targets.length; i++) { var related = isRelatedTo(sources[i], targets[i], reportErrors); if (!related) { return 0 /* False */; } result &= related; } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
typeArgumentsRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function typeParameterIdenticalTo(source, target) { // covers case when both type parameters does not have constraint (both equal to noConstraintType) if (source.constraint === target.constraint) { return -1 /* True */; } if (source.constraint === noConstraintType || target.constraint === noConstraintType) { return 0 /* False */; } return isIdenticalTo(source.constraint, target.constraint); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
typeParameterIdenticalTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function objectTypeRelatedTo(apparentSource, originalSource, target, reportErrors) { if (overflow) { return 0 /* False */; } var id = relation !== identityRelation || apparentSource.id < target.id ? apparentSource.id + "," + target.id : target.id + "," + apparentSource.id; var related = relation[id]; if (related !== undefined) { // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate // errors, we can use the cached value. Otherwise, recompute the relation if (!elaborateErrors || (related === 3 /* FailedAndReported */)) { return related === 1 /* Succeeded */ ? -1 /* True */ : 0 /* False */; } } if (depth > 0) { for (var i = 0; i < depth; i++) { // If source and target are already being compared, consider them related with assumptions if (maybeStack[i][id]) { return 1 /* Maybe */; } } if (depth === 100) { overflow = true; return 0 /* False */; } } else { sourceStack = []; targetStack = []; maybeStack = []; expandingFlags = 0; } sourceStack[depth] = apparentSource; targetStack[depth] = target; maybeStack[depth] = {}; maybeStack[depth][id] = 1 /* Succeeded */; depth++; var saveExpandingFlags = expandingFlags; if (!(expandingFlags & 1) && isDeeplyNestedGeneric(apparentSource, sourceStack, depth)) expandingFlags |= 1; if (!(expandingFlags & 2) && isDeeplyNestedGeneric(target, targetStack, depth)) expandingFlags |= 2; var result; if (expandingFlags === 3) { result = 1 /* Maybe */; } else { result = propertiesRelatedTo(apparentSource, target, reportErrors); if (result) { result &= signaturesRelatedTo(apparentSource, target, 0 /* Call */, reportErrors); if (result) { result &= signaturesRelatedTo(apparentSource, target, 1 /* Construct */, reportErrors); if (result) { result &= stringIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); if (result) { result &= numberIndexTypesRelatedTo(apparentSource, originalSource, target, reportErrors); } } } } } expandingFlags = saveExpandingFlags; depth--; if (result) { var maybeCache = maybeStack[depth]; // If result is definitely true, copy assumptions to global cache, else copy to next level up var destinationCache = (result === -1 /* True */ || depth === 0) ? relation : maybeStack[depth - 1]; ts.copyMap(maybeCache, destinationCache); } else { // A false result goes straight into global cache (when something is false under assumptions it // will also be false without assumptions) relation[id] = reportErrors ? 3 /* FailedAndReported */ : 2 /* Failed */; } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
objectTypeRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function propertiesRelatedTo(source, target, reportErrors) { if (relation === identityRelation) { return propertiesIdenticalTo(source, target); } var result = -1 /* True */; var properties = getPropertiesOfObjectType(target); var requireOptionalProperties = relation === subtypeRelation && !(source.flags & 524288 /* ObjectLiteral */); for (var _i = 0, properties_1 = properties; _i < properties_1.length; _i++) { var targetProp = properties_1[_i]; var sourceProp = getPropertyOfType(source, targetProp.name); if (sourceProp !== targetProp) { if (!sourceProp) { if (!(targetProp.flags & 536870912 /* Optional */) || requireOptionalProperties) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); } return 0 /* False */; } } else if (!(targetProp.flags & 134217728 /* Prototype */)) { var sourcePropFlags = getDeclarationFlagsFromSymbol(sourceProp); var targetPropFlags = getDeclarationFlagsFromSymbol(targetProp); if (sourcePropFlags & 16 /* Private */ || targetPropFlags & 16 /* Private */) { if (sourceProp.valueDeclaration !== targetProp.valueDeclaration) { if (reportErrors) { if (sourcePropFlags & 16 /* Private */ && targetPropFlags & 16 /* Private */) { reportError(ts.Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp)); } else { reportError(ts.Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), typeToString(sourcePropFlags & 16 /* Private */ ? source : target), typeToString(sourcePropFlags & 16 /* Private */ ? target : source)); } } return 0 /* False */; } } else if (targetPropFlags & 32 /* Protected */) { var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & 32 /* Class */; var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined; var targetClass = getDeclaredTypeOfSymbol(targetProp.parent); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } return 0 /* False */; } } else if (sourcePropFlags & 32 /* Protected */) { if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } var related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp)); } return 0 /* False */; } result &= related; if (sourceProp.flags & 536870912 /* Optional */ && !(targetProp.flags & 536870912 /* Optional */)) { // TypeScript 1.0 spec (April 2014): 3.8.3 // S is a subtype of a type T, and T is a supertype of S if ... // S' and T are object types and, for each member M in T.. // M is a property and S' contains a property N where // if M is a required property, N is also a required property // (M - property in T) // (N - property in S) if (reportErrors) { reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target)); } return 0 /* False */; } } } } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
propertiesRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function propertiesIdenticalTo(source, target) { if (!(source.flags & 80896 /* ObjectType */ && target.flags & 80896 /* ObjectType */)) { return 0 /* False */; } var sourceProperties = getPropertiesOfObjectType(source); var targetProperties = getPropertiesOfObjectType(target); if (sourceProperties.length !== targetProperties.length) { return 0 /* False */; } var result = -1 /* True */; for (var _i = 0, sourceProperties_1 = sourceProperties; _i < sourceProperties_1.length; _i++) { var sourceProp = sourceProperties_1[_i]; var targetProp = getPropertyOfObjectType(target, sourceProp.name); if (!targetProp) { return 0 /* False */; } var related = compareProperties(sourceProp, targetProp, isRelatedTo); if (!related) { return 0 /* False */; } result &= related; } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
propertiesIdenticalTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function signaturesRelatedTo(source, target, kind, reportErrors) { if (relation === identityRelation) { return signaturesIdenticalTo(source, target, kind); } if (target === anyFunctionType || source === anyFunctionType) { return -1 /* True */; } var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); var result = -1 /* True */; var saveErrorInfo = errorInfo; if (kind === 1 /* Construct */) { // Only want to compare the construct signatures for abstractness guarantees. // Because the "abstractness" of a class is the same across all construct signatures // (internally we are checking the corresponding declaration), it is enough to perform // the check and report an error once over all pairs of source and target construct signatures. // // sourceSig and targetSig are (possibly) undefined. // // Note that in an extends-clause, targetSignatures is stripped, so the check never proceeds. var sourceSig = sourceSignatures[0]; var targetSig = targetSignatures[0]; result &= abstractSignatureRelatedTo(source, sourceSig, target, targetSig); if (result !== -1 /* True */) { return result; } } outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) { var t = targetSignatures_1[_i]; if (!t.hasStringLiterals || target.flags & 262144 /* FromSignature */) { var localErrors = reportErrors; var checkedAbstractAssignability = false; for (var _a = 0, sourceSignatures_1 = sourceSignatures; _a < sourceSignatures_1.length; _a++) { var s = sourceSignatures_1[_a]; if (!s.hasStringLiterals || source.flags & 262144 /* FromSignature */) { var related = signatureRelatedTo(s, t, localErrors); if (related) { result &= related; errorInfo = saveErrorInfo; continue outer; } // Only report errors from the first failure localErrors = false; } } return 0 /* False */; } } return result; function abstractSignatureRelatedTo(source, sourceSig, target, targetSig) { if (sourceSig && targetSig) { var sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol); var targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol); if (!sourceDecl) { // If the source object isn't itself a class declaration, it can be freely assigned, regardless // of whether the constructed object is abstract or not. return -1 /* True */; } var sourceErasedSignature = getErasedSignature(sourceSig); var targetErasedSignature = getErasedSignature(targetSig); var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol); var targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol); var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 128 /* Abstract */; var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 128 /* Abstract */; if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) { // if target isn't a class-declaration type, then it can be new'd, so we forbid the assignment. if (reportErrors) { reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); } return 0 /* False */; } } return -1 /* True */; } }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
signaturesRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function abstractSignatureRelatedTo(source, sourceSig, target, targetSig) { if (sourceSig && targetSig) { var sourceDecl = source.symbol && getClassLikeDeclarationOfSymbol(source.symbol); var targetDecl = target.symbol && getClassLikeDeclarationOfSymbol(target.symbol); if (!sourceDecl) { // If the source object isn't itself a class declaration, it can be freely assigned, regardless // of whether the constructed object is abstract or not. return -1 /* True */; } var sourceErasedSignature = getErasedSignature(sourceSig); var targetErasedSignature = getErasedSignature(targetSig); var sourceReturnType = sourceErasedSignature && getReturnTypeOfSignature(sourceErasedSignature); var targetReturnType = targetErasedSignature && getReturnTypeOfSignature(targetErasedSignature); var sourceReturnDecl = sourceReturnType && sourceReturnType.symbol && getClassLikeDeclarationOfSymbol(sourceReturnType.symbol); var targetReturnDecl = targetReturnType && targetReturnType.symbol && getClassLikeDeclarationOfSymbol(targetReturnType.symbol); var sourceIsAbstract = sourceReturnDecl && sourceReturnDecl.flags & 128 /* Abstract */; var targetIsAbstract = targetReturnDecl && targetReturnDecl.flags & 128 /* Abstract */; if (sourceIsAbstract && !(targetIsAbstract && targetDecl)) { // if target isn't a class-declaration type, then it can be new'd, so we forbid the assignment. if (reportErrors) { reportError(ts.Diagnostics.Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type); } return 0 /* False */; } } return -1 /* True */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
abstractSignatureRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function signatureRelatedTo(source, target, reportErrors) { if (source === target) { return -1 /* True */; } if (!target.hasRestParameter && source.minArgumentCount > target.parameters.length) { return 0 /* False */; } var sourceMax = source.parameters.length; var targetMax = target.parameters.length; var checkCount; if (source.hasRestParameter && target.hasRestParameter) { checkCount = sourceMax > targetMax ? sourceMax : targetMax; sourceMax--; targetMax--; } else if (source.hasRestParameter) { sourceMax--; checkCount = targetMax; } else if (target.hasRestParameter) { targetMax--; checkCount = sourceMax; } else { checkCount = sourceMax < targetMax ? sourceMax : targetMax; } // Spec 1.0 Section 3.8.3 & 3.8.4: // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N source = getErasedSignature(source); target = getErasedSignature(target); var result = -1 /* True */; for (var i = 0; i < checkCount; i++) { var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); var saveErrorInfo = errorInfo; var related = isRelatedTo(s, t, reportErrors); if (!related) { related = isRelatedTo(t, s, false); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Types_of_parameters_0_and_1_are_incompatible, source.parameters[i < sourceMax ? i : sourceMax].name, target.parameters[i < targetMax ? i : targetMax].name); } return 0 /* False */; } errorInfo = saveErrorInfo; } result &= related; } if (source.typePredicate && target.typePredicate) { var hasDifferentParameterIndex = source.typePredicate.parameterIndex !== target.typePredicate.parameterIndex; var hasDifferentTypes; if (hasDifferentParameterIndex || (hasDifferentTypes = !isTypeIdenticalTo(source.typePredicate.type, target.typePredicate.type))) { if (reportErrors) { var sourceParamText = source.typePredicate.parameterName; var targetParamText = target.typePredicate.parameterName; var sourceTypeText = typeToString(source.typePredicate.type); var targetTypeText = typeToString(target.typePredicate.type); if (hasDifferentParameterIndex) { reportError(ts.Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, sourceParamText, targetParamText); } else if (hasDifferentTypes) { reportError(ts.Diagnostics.Type_0_is_not_assignable_to_type_1, sourceTypeText, targetTypeText); } reportError(ts.Diagnostics.Type_predicate_0_is_not_assignable_to_1, sourceParamText + " is " + sourceTypeText, targetParamText + " is " + targetTypeText); } return 0 /* False */; } } else if (!source.typePredicate && target.typePredicate) { if (reportErrors) { reportError(ts.Diagnostics.Signature_0_must_have_a_type_predicate, signatureToString(source)); } return 0 /* False */; } var targetReturnType = getReturnTypeOfSignature(target); if (targetReturnType === voidType) return result; var sourceReturnType = getReturnTypeOfSignature(source); return result & isRelatedTo(sourceReturnType, targetReturnType, reportErrors); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
signatureRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function signaturesIdenticalTo(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); if (sourceSignatures.length !== targetSignatures.length) { return 0 /* False */; } var result = -1 /* True */; for (var i = 0, len = sourceSignatures.length; i < len; ++i) { var related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); if (!related) { return 0 /* False */; } result &= related; } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
signaturesIdenticalTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function stringIndexTypesRelatedTo(source, originalSource, target, reportErrors) { if (relation === identityRelation) { return indexTypesIdenticalTo(0 /* String */, source, target); } var targetType = getIndexTypeOfType(target, 0 /* String */); if (targetType) { if ((targetType.flags & 1 /* Any */) && !(originalSource.flags & 16777726 /* Primitive */)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: string]: any } = { property: 12 };` return -1 /* True */; } var sourceType = getIndexTypeOfType(source, 0 /* String */); if (!sourceType) { if (reportErrors) { reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return 0 /* False */; } var related = isRelatedTo(sourceType, targetType, reportErrors); if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Index_signatures_are_incompatible); } return 0 /* False */; } return related; } return -1 /* True */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
stringIndexTypesRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function numberIndexTypesRelatedTo(source, originalSource, target, reportErrors) { if (relation === identityRelation) { return indexTypesIdenticalTo(1 /* Number */, source, target); } var targetType = getIndexTypeOfType(target, 1 /* Number */); if (targetType) { if ((targetType.flags & 1 /* Any */) && !(originalSource.flags & 16777726 /* Primitive */)) { // non-primitive assignment to any is always allowed, eg // `var x: { [index: number]: any } = { property: 12 };` return -1 /* True */; } var sourceStringType = getIndexTypeOfType(source, 0 /* String */); var sourceNumberType = getIndexTypeOfType(source, 1 /* Number */); if (!(sourceStringType || sourceNumberType)) { if (reportErrors) { reportError(ts.Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return 0 /* False */; } var related; if (sourceStringType && sourceNumberType) { // If we know for sure we're testing both string and numeric index types then only report errors from the second one related = isRelatedTo(sourceStringType, targetType, false) || isRelatedTo(sourceNumberType, targetType, reportErrors); } else { related = isRelatedTo(sourceStringType || sourceNumberType, targetType, reportErrors); } if (!related) { if (reportErrors) { reportError(ts.Diagnostics.Index_signatures_are_incompatible); } return 0 /* False */; } return related; } return -1 /* True */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
numberIndexTypesRelatedTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function indexTypesIdenticalTo(indexKind, source, target) { var targetType = getIndexTypeOfType(target, indexKind); var sourceType = getIndexTypeOfType(source, indexKind); if (!sourceType && !targetType) { return -1 /* True */; } if (sourceType && targetType) { return isRelatedTo(sourceType, targetType); } return 0 /* False */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
indexTypesIdenticalTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isPropertyIdenticalTo(sourceProp, targetProp) { return compareProperties(sourceProp, targetProp, compareTypes) !== 0 /* False */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isPropertyIdenticalTo
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function compareProperties(sourceProp, targetProp, compareTypes) { // Two members are considered identical when // - they are public properties with identical names, optionality, and types, // - they are private or protected properties originating in the same declaration and having identical types if (sourceProp === targetProp) { return -1 /* True */; } var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (16 /* Private */ | 32 /* Protected */); var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (16 /* Private */ | 32 /* Protected */); if (sourcePropAccessibility !== targetPropAccessibility) { return 0 /* False */; } if (sourcePropAccessibility) { if (getTargetSymbol(sourceProp) !== getTargetSymbol(targetProp)) { return 0 /* False */; } } else { if ((sourceProp.flags & 536870912 /* Optional */) !== (targetProp.flags & 536870912 /* Optional */)) { return 0 /* False */; } } return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
compareProperties
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isMatchingSignature(source, target, partialMatch) { // A source signature matches a target signature if the two signatures have the same number of required, // optional, and rest parameters. if (source.parameters.length === target.parameters.length && source.minArgumentCount === target.minArgumentCount && source.hasRestParameter === target.hasRestParameter) { return true; } // A source signature partially matches a target signature if the target signature has no fewer required // parameters and no more overall parameters than the source signature (where a signature with a rest // parameter is always considered to have more overall parameters than one without). if (partialMatch && source.minArgumentCount <= target.minArgumentCount && (source.hasRestParameter && !target.hasRestParameter || source.hasRestParameter === target.hasRestParameter && source.parameters.length >= target.parameters.length)) { return true; } return false; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isMatchingSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function compareSignatures(source, target, partialMatch, ignoreReturnTypes, compareTypes) { if (source === target) { return -1 /* True */; } if (!(isMatchingSignature(source, target, partialMatch))) { return 0 /* False */; } var result = -1 /* True */; if (source.typeParameters && target.typeParameters) { if (source.typeParameters.length !== target.typeParameters.length) { return 0 /* False */; } for (var i = 0, len = source.typeParameters.length; i < len; ++i) { var related = compareTypes(source.typeParameters[i], target.typeParameters[i]); if (!related) { return 0 /* False */; } result &= related; } } else if (source.typeParameters || target.typeParameters) { return 0 /* False */; } // Spec 1.0 Section 3.8.3 & 3.8.4: // M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N source = getErasedSignature(source); target = getErasedSignature(target); var targetLen = target.parameters.length; for (var i = 0; i < targetLen; i++) { var s = isRestParameterIndex(source, i) ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]); var t = isRestParameterIndex(target, i) ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]); var related = compareTypes(s, t); if (!related) { return 0 /* False */; } result &= related; } if (!ignoreReturnTypes) { result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); } return result; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
compareSignatures
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isRestParameterIndex(signature, parameterIndex) { return signature.hasRestParameter && parameterIndex >= signature.parameters.length - 1; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isRestParameterIndex
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isSupertypeOfEach(candidate, types) { for (var _i = 0, types_6 = types; _i < types_6.length; _i++) { var type = types_6[_i]; if (candidate !== type && !isTypeSubtypeOf(type, candidate)) return false; } return true; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isSupertypeOfEach
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getCommonSupertype(types) { return ts.forEach(types, function (t) { return isSupertypeOfEach(t, types) ? t : undefined; }); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
getCommonSupertype
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function reportNoCommonSupertypeError(types, errorLocation, errorMessageChainHead) { // The downfallType/bestSupertypeDownfallType is the first type that caused a particular candidate // to not be the common supertype. So if it weren't for this one downfallType (and possibly others), // the type in question could have been the common supertype. var bestSupertype; var bestSupertypeDownfallType; var bestSupertypeScore = 0; for (var i = 0; i < types.length; i++) { var score = 0; var downfallType = undefined; for (var j = 0; j < types.length; j++) { if (isTypeSubtypeOf(types[j], types[i])) { score++; } else if (!downfallType) { downfallType = types[j]; } } ts.Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType"); if (score > bestSupertypeScore) { bestSupertype = types[i]; bestSupertypeDownfallType = downfallType; bestSupertypeScore = score; } // types.length - 1 is the maximum score, given that getCommonSupertype returned false if (bestSupertypeScore === types.length - 1) { break; } } // In the following errors, the {1} slot is before the {0} slot because checkTypeSubtypeOf supplies the // subtype as the first argument to the error checkTypeSubtypeOf(bestSupertypeDownfallType, bestSupertype, errorLocation, ts.Diagnostics.Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0, errorMessageChainHead); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
reportNoCommonSupertypeError
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isArrayType(type) { return type.flags & 4096 /* Reference */ && type.target === globalArrayType; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isArrayType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isArrayLikeType(type) { // A type is array-like if it is not the undefined or null type and if it is assignable to any[] return !(type.flags & (32 /* Undefined */ | 64 /* Null */)) && isTypeAssignableTo(type, anyArrayType); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isArrayLikeType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isTupleLikeType(type) { return !!getPropertyOfType(type, "0"); }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isTupleLikeType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isStringLiteralType(type) { return type.flags & 256 /* StringLiteral */; }
Checks if 'source' is related to 'target' (e.g.: is a assignable to). @param source The left-hand-side of the relation. @param target The right-hand-side of the relation. @param relation The relation considered. One of 'identityRelation', 'assignableRelation', or 'subTypeRelation'. Used as both to determine which checks are performed and as a cache of previously computed results. @param errorNode The suggested node upon which all errors will be reported, if defined. This may or may not be the actual node used. @param headMessage If the error chain should be prepended by a head message, then headMessage will be used. @param containingMessageChain A chain of errors to prepend any new errors found.
isStringLiteralType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isTupleType(type) { return !!(type.flags & 8192 /* Tuple */); }
Check if a Type was written as a tuple type literal. Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
isTupleType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getRegularTypeOfObjectLiteral(type) { if (type.flags & 1048576 /* FreshObjectLiteral */) { var regularType = type.regularType; if (!regularType) { regularType = createType(type.flags & ~1048576 /* FreshObjectLiteral */); regularType.symbol = type.symbol; regularType.members = type.members; regularType.properties = type.properties; regularType.callSignatures = type.callSignatures; regularType.constructSignatures = type.constructSignatures; regularType.stringIndexType = type.stringIndexType; regularType.numberIndexType = type.numberIndexType; type.regularType = regularType; } return regularType; } return type; }
Check if a Type was written as a tuple type literal. Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
getRegularTypeOfObjectLiteral
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getWidenedTypeOfObjectLiteral(type) { var properties = getPropertiesOfObjectType(type); var members = {}; ts.forEach(properties, function (p) { var propType = getTypeOfSymbol(p); var widenedType = getWidenedType(propType); if (propType !== widenedType) { var symbol = createSymbol(p.flags | 67108864 /* Transient */, p.name); symbol.declarations = p.declarations; symbol.parent = p.parent; symbol.type = widenedType; symbol.target = p; if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration; p = symbol; } members[p.name] = p; }); var stringIndexType = getIndexTypeOfType(type, 0 /* String */); var numberIndexType = getIndexTypeOfType(type, 1 /* Number */); if (stringIndexType) stringIndexType = getWidenedType(stringIndexType); if (numberIndexType) numberIndexType = getWidenedType(numberIndexType); return createAnonymousType(type.symbol, members, emptyArray, emptyArray, stringIndexType, numberIndexType); }
Check if a Type was written as a tuple type literal. Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
getWidenedTypeOfObjectLiteral
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getWidenedType(type) { if (type.flags & 6291456 /* RequiresWidening */) { if (type.flags & (32 /* Undefined */ | 64 /* Null */)) { return anyType; } if (type.flags & 524288 /* ObjectLiteral */) { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & 16384 /* Union */) { return getUnionType(ts.map(type.types, getWidenedType), /*noSubtypeReduction*/ true); } if (isArrayType(type)) { return createArrayType(getWidenedType(type.typeArguments[0])); } if (isTupleType(type)) { return createTupleType(ts.map(type.elementTypes, getWidenedType)); } } return type; }
Check if a Type was written as a tuple type literal. Prefer using isTupleLikeType() unless the use of `elementTypes` is required.
getWidenedType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function reportWideningErrorsInType(type) { var errorReported = false; if (type.flags & 16384 /* Union */) { for (var _i = 0, _a = type.types; _i < _a.length; _i++) { var t = _a[_i]; if (reportWideningErrorsInType(t)) { errorReported = true; } } } if (isArrayType(type)) { return reportWideningErrorsInType(type.typeArguments[0]); } if (isTupleType(type)) { for (var _b = 0, _c = type.elementTypes; _b < _c.length; _b++) { var t = _c[_b]; if (reportWideningErrorsInType(t)) { errorReported = true; } } } if (type.flags & 524288 /* ObjectLiteral */) { for (var _d = 0, _e = getPropertiesOfObjectType(type); _d < _e.length; _d++) { var p = _e[_d]; var t = getTypeOfSymbol(p); if (t.flags & 2097152 /* ContainsUndefinedOrNull */) { if (!reportWideningErrorsInType(t)) { error(p.valueDeclaration, ts.Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t))); } errorReported = true; } } } return errorReported; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
reportWideningErrorsInType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function reportImplicitAnyError(declaration, type) { var typeAsString = typeToString(getWidenedType(type)); var diagnostic; switch (declaration.kind) { case 141 /* PropertyDeclaration */: case 140 /* PropertySignature */: diagnostic = ts.Diagnostics.Member_0_implicitly_has_an_1_type; break; case 138 /* Parameter */: diagnostic = declaration.dotDotDotToken ? ts.Diagnostics.Rest_parameter_0_implicitly_has_an_any_type : ts.Diagnostics.Parameter_0_implicitly_has_an_1_type; break; case 213 /* FunctionDeclaration */: case 143 /* MethodDeclaration */: case 142 /* MethodSignature */: case 145 /* GetAccessor */: case 146 /* SetAccessor */: case 173 /* FunctionExpression */: case 174 /* ArrowFunction */: if (!declaration.name) { error(declaration, ts.Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); return; } diagnostic = ts.Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type; break; default: diagnostic = ts.Diagnostics.Variable_0_implicitly_has_an_1_type; } error(declaration, diagnostic, ts.declarationNameToString(declaration.name), typeAsString); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
reportImplicitAnyError
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function reportErrorsFromWidening(declaration, type) { if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & 2097152 /* ContainsUndefinedOrNull */) { // Report implicit any error within type if possible, otherwise report error on declaration if (!reportWideningErrorsInType(type)) { reportImplicitAnyError(declaration, type); } } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
reportErrorsFromWidening
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function forEachMatchingParameterType(source, target, callback) { var sourceMax = source.parameters.length; var targetMax = target.parameters.length; var count; if (source.hasRestParameter && target.hasRestParameter) { count = sourceMax > targetMax ? sourceMax : targetMax; sourceMax--; targetMax--; } else if (source.hasRestParameter) { sourceMax--; count = targetMax; } else if (target.hasRestParameter) { targetMax--; count = sourceMax; } else { count = sourceMax < targetMax ? sourceMax : targetMax; } for (var i = 0; i < count; i++) { var s = i < sourceMax ? getTypeOfSymbol(source.parameters[i]) : getRestTypeOfSignature(source); var t = i < targetMax ? getTypeOfSymbol(target.parameters[i]) : getRestTypeOfSignature(target); callback(s, t); } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
forEachMatchingParameterType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function createInferenceContext(typeParameters, inferUnionTypes) { var inferences = []; for (var _i = 0, typeParameters_1 = typeParameters; _i < typeParameters_1.length; _i++) { var unused = typeParameters_1[_i]; inferences.push({ primary: undefined, secondary: undefined, isFixed: false }); } return { typeParameters: typeParameters, inferUnionTypes: inferUnionTypes, inferences: inferences, inferredTypes: new Array(typeParameters.length) }; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
createInferenceContext
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function inferTypes(context, source, target) { var sourceStack; var targetStack; var depth = 0; var inferiority = 0; inferFromTypes(source, target); function isInProcess(source, target) { for (var i = 0; i < depth; i++) { if (source === sourceStack[i] && target === targetStack[i]) { return true; } } return false; } function inferFromTypes(source, target) { if (target.flags & 512 /* TypeParameter */) { // If target is a type parameter, make an inference, unless the source type contains // the anyFunctionType (the wildcard type that's used to avoid contextually typing functions). // Because the anyFunctionType is internal, it should not be exposed to the user by adding // it as an inference candidate. Hopefully, a better candidate will come along that does // not contain anyFunctionType when we come back to this argument for its second round // of inference. if (source.flags & 8388608 /* ContainsAnyFunctionType */) { return; } var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { var inferences = context.inferences[i]; if (!inferences.isFixed) { // Any inferences that are made to a type parameter in a union type are inferior // to inferences made to a flat (non-union) type. This is because if we infer to // T | string[], we really don't know if we should be inferring to T or not (because // the correct constituent on the target side could be string[]). Therefore, we put // such inferior inferences into a secondary bucket, and only use them if the primary // bucket is empty. var candidates = inferiority ? inferences.secondary || (inferences.secondary = []) : inferences.primary || (inferences.primary = []); if (!ts.contains(candidates, source)) { candidates.push(source); } } return; } } } else if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // If source and target are references to the same generic type, infer from type arguments var sourceTypes = source.typeArguments || emptyArray; var targetTypes = target.typeArguments || emptyArray; var count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length; for (var i = 0; i < count; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } else if (source.flags & 8192 /* Tuple */ && target.flags & 8192 /* Tuple */ && source.elementTypes.length === target.elementTypes.length) { // If source and target are tuples of the same size, infer from element types var sourceTypes = source.elementTypes; var targetTypes = target.elementTypes; for (var i = 0; i < sourceTypes.length; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } else if (target.flags & 49152 /* UnionOrIntersection */) { var targetTypes = target.types; var typeParameterCount = 0; var typeParameter; // First infer to each type in union or intersection that isn't a type parameter for (var _i = 0, targetTypes_2 = targetTypes; _i < targetTypes_2.length; _i++) { var t = targetTypes_2[_i]; if (t.flags & 512 /* TypeParameter */ && ts.contains(context.typeParameters, t)) { typeParameter = t; typeParameterCount++; } else { inferFromTypes(source, t); } } // Next, if target is a union type containing a single naked type parameter, make a // secondary inference to that type parameter. We don't do this for intersection types // because in a target type like Foo & T we don't know how which parts of the source type // should be matched by Foo and which should be inferred to T. if (target.flags & 16384 /* Union */ && typeParameterCount === 1) { inferiority++; inferFromTypes(source, typeParameter); inferiority--; } } else if (source.flags & 49152 /* UnionOrIntersection */) { // Source is a union or intersection type, infer from each consituent type var sourceTypes = source.types; for (var _a = 0, sourceTypes_3 = sourceTypes; _a < sourceTypes_3.length; _a++) { var sourceType = sourceTypes_3[_a]; inferFromTypes(sourceType, target); } } else { source = getApparentType(source); if (source.flags & 80896 /* ObjectType */ && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 65536 /* Anonymous */) && target.symbol && target.symbol.flags & (8192 /* Method */ | 2048 /* TypeLiteral */ | 32 /* Class */))) { // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members if (isInProcess(source, target)) { return; } if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { return; } if (depth === 0) { sourceStack = []; targetStack = []; } sourceStack[depth] = source; targetStack[depth] = target; depth++; inferFromProperties(source, target); inferFromSignatures(source, target, 0 /* Call */); inferFromSignatures(source, target, 1 /* Construct */); inferFromIndexTypes(source, target, 0 /* String */, 0 /* String */); inferFromIndexTypes(source, target, 1 /* Number */, 1 /* Number */); inferFromIndexTypes(source, target, 0 /* String */, 1 /* Number */); depth--; } } } function inferFromProperties(source, target) { var properties = getPropertiesOfObjectType(target); for (var _i = 0, properties_2 = properties; _i < properties_2.length; _i++) { var targetProp = properties_2[_i]; var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } } } function inferFromSignatures(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); var sourceLen = sourceSignatures.length; var targetLen = targetSignatures.length; var len = sourceLen < targetLen ? sourceLen : targetLen; for (var i = 0; i < len; i++) { inferFromSignature(getErasedSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i])); } } function inferFromSignature(source, target) { forEachMatchingParameterType(source, target, inferFromTypes); if (source.typePredicate && target.typePredicate) { if (target.typePredicate.parameterIndex === source.typePredicate.parameterIndex) { // Return types from type predicates are treated as booleans. In order to infer types // from type predicates we would need to infer using the type within the type predicate // (i.e. 'Foo' from 'x is Foo'). inferFromTypes(source.typePredicate.type, target.typePredicate.type); } } else { inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); } } function inferFromIndexTypes(source, target, sourceKind, targetKind) { var targetIndexType = getIndexTypeOfType(target, targetKind); if (targetIndexType) { var sourceIndexType = getIndexTypeOfType(source, sourceKind); if (sourceIndexType) { inferFromTypes(sourceIndexType, targetIndexType); } } } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
inferTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInProcess(source, target) { for (var i = 0; i < depth; i++) { if (source === sourceStack[i] && target === targetStack[i]) { return true; } } return false; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isInProcess
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function inferFromTypes(source, target) { if (target.flags & 512 /* TypeParameter */) { // If target is a type parameter, make an inference, unless the source type contains // the anyFunctionType (the wildcard type that's used to avoid contextually typing functions). // Because the anyFunctionType is internal, it should not be exposed to the user by adding // it as an inference candidate. Hopefully, a better candidate will come along that does // not contain anyFunctionType when we come back to this argument for its second round // of inference. if (source.flags & 8388608 /* ContainsAnyFunctionType */) { return; } var typeParameters = context.typeParameters; for (var i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { var inferences = context.inferences[i]; if (!inferences.isFixed) { // Any inferences that are made to a type parameter in a union type are inferior // to inferences made to a flat (non-union) type. This is because if we infer to // T | string[], we really don't know if we should be inferring to T or not (because // the correct constituent on the target side could be string[]). Therefore, we put // such inferior inferences into a secondary bucket, and only use them if the primary // bucket is empty. var candidates = inferiority ? inferences.secondary || (inferences.secondary = []) : inferences.primary || (inferences.primary = []); if (!ts.contains(candidates, source)) { candidates.push(source); } } return; } } } else if (source.flags & 4096 /* Reference */ && target.flags & 4096 /* Reference */ && source.target === target.target) { // If source and target are references to the same generic type, infer from type arguments var sourceTypes = source.typeArguments || emptyArray; var targetTypes = target.typeArguments || emptyArray; var count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length; for (var i = 0; i < count; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } else if (source.flags & 8192 /* Tuple */ && target.flags & 8192 /* Tuple */ && source.elementTypes.length === target.elementTypes.length) { // If source and target are tuples of the same size, infer from element types var sourceTypes = source.elementTypes; var targetTypes = target.elementTypes; for (var i = 0; i < sourceTypes.length; i++) { inferFromTypes(sourceTypes[i], targetTypes[i]); } } else if (target.flags & 49152 /* UnionOrIntersection */) { var targetTypes = target.types; var typeParameterCount = 0; var typeParameter; // First infer to each type in union or intersection that isn't a type parameter for (var _i = 0, targetTypes_2 = targetTypes; _i < targetTypes_2.length; _i++) { var t = targetTypes_2[_i]; if (t.flags & 512 /* TypeParameter */ && ts.contains(context.typeParameters, t)) { typeParameter = t; typeParameterCount++; } else { inferFromTypes(source, t); } } // Next, if target is a union type containing a single naked type parameter, make a // secondary inference to that type parameter. We don't do this for intersection types // because in a target type like Foo & T we don't know how which parts of the source type // should be matched by Foo and which should be inferred to T. if (target.flags & 16384 /* Union */ && typeParameterCount === 1) { inferiority++; inferFromTypes(source, typeParameter); inferiority--; } } else if (source.flags & 49152 /* UnionOrIntersection */) { // Source is a union or intersection type, infer from each consituent type var sourceTypes = source.types; for (var _a = 0, sourceTypes_3 = sourceTypes; _a < sourceTypes_3.length; _a++) { var sourceType = sourceTypes_3[_a]; inferFromTypes(sourceType, target); } } else { source = getApparentType(source); if (source.flags & 80896 /* ObjectType */ && (target.flags & (4096 /* Reference */ | 8192 /* Tuple */) || (target.flags & 65536 /* Anonymous */) && target.symbol && target.symbol.flags & (8192 /* Method */ | 2048 /* TypeLiteral */ | 32 /* Class */))) { // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members if (isInProcess(source, target)) { return; } if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { return; } if (depth === 0) { sourceStack = []; targetStack = []; } sourceStack[depth] = source; targetStack[depth] = target; depth++; inferFromProperties(source, target); inferFromSignatures(source, target, 0 /* Call */); inferFromSignatures(source, target, 1 /* Construct */); inferFromIndexTypes(source, target, 0 /* String */, 0 /* String */); inferFromIndexTypes(source, target, 1 /* Number */, 1 /* Number */); inferFromIndexTypes(source, target, 0 /* String */, 1 /* Number */); depth--; } } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
inferFromTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function inferFromProperties(source, target) { var properties = getPropertiesOfObjectType(target); for (var _i = 0, properties_2 = properties; _i < properties_2.length; _i++) { var targetProp = properties_2[_i]; var sourceProp = getPropertyOfObjectType(source, targetProp.name); if (sourceProp) { inferFromTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
inferFromProperties
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function inferFromSignatures(source, target, kind) { var sourceSignatures = getSignaturesOfType(source, kind); var targetSignatures = getSignaturesOfType(target, kind); var sourceLen = sourceSignatures.length; var targetLen = targetSignatures.length; var len = sourceLen < targetLen ? sourceLen : targetLen; for (var i = 0; i < len; i++) { inferFromSignature(getErasedSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i])); } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
inferFromSignatures
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function inferFromSignature(source, target) { forEachMatchingParameterType(source, target, inferFromTypes); if (source.typePredicate && target.typePredicate) { if (target.typePredicate.parameterIndex === source.typePredicate.parameterIndex) { // Return types from type predicates are treated as booleans. In order to infer types // from type predicates we would need to infer using the type within the type predicate // (i.e. 'Foo' from 'x is Foo'). inferFromTypes(source.typePredicate.type, target.typePredicate.type); } } else { inferFromTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target)); } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
inferFromSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function inferFromIndexTypes(source, target, sourceKind, targetKind) { var targetIndexType = getIndexTypeOfType(target, targetKind); if (targetIndexType) { var sourceIndexType = getIndexTypeOfType(source, sourceKind); if (sourceIndexType) { inferFromTypes(sourceIndexType, targetIndexType); } } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
inferFromIndexTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getInferenceCandidates(context, index) { var inferences = context.inferences[index]; return inferences.primary || inferences.secondary || emptyArray; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getInferenceCandidates
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getInferredType(context, index) { var inferredType = context.inferredTypes[index]; var inferenceSucceeded; if (!inferredType) { var inferences = getInferenceCandidates(context, index); if (inferences.length) { // Infer widened union or supertype, or the unknown type for no common supertype var unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType; inferenceSucceeded = !!unionOrSuperType; } else { // Infer the empty object type when no inferences were made. It is important to remember that // in this case, inference still succeeds, meaning there is no error for not having inference // candidates. An inference error only occurs when there are *conflicting* candidates, i.e. // candidates with no common supertype. inferredType = emptyObjectType; inferenceSucceeded = true; } // Only do the constraint check if inference succeeded (to prevent cascading errors) if (inferenceSucceeded) { var constraint = getConstraintOfTypeParameter(context.typeParameters[index]); inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; } else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) { // If inference failed, it is necessary to record the index of the failed type parameter (the one we are on). // It might be that inference has already failed on a later type parameter on a previous call to inferTypeArguments. // So if this failure is on preceding type parameter, this type parameter is the new failure index. context.failedTypeParameterIndex = index; } context.inferredTypes[index] = inferredType; } return inferredType; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getInferredType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getInferredTypes(context) { for (var i = 0; i < context.inferredTypes.length; i++) { getInferredType(context, i); } return context.inferredTypes; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getInferredTypes
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function hasAncestor(node, kind) { return ts.getAncestor(node, kind) !== undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
hasAncestor
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getResolvedSymbol(node) { var links = getNodeLinks(node); if (!links.resolvedSymbol) { links.resolvedSymbol = (!ts.nodeIsMissing(node) && resolveName(node, node.text, 107455 /* Value */ | 1048576 /* ExportValue */, ts.Diagnostics.Cannot_find_name_0, node)) || unknownSymbol; } return links.resolvedSymbol; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getResolvedSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInTypeQuery(node) { // TypeScript 1.0 spec (April 2014): 3.6.3 // A type query consists of the keyword typeof followed by an expression. // The expression is restricted to a single identifier or a sequence of identifiers separated by periods while (node) { switch (node.kind) { case 154 /* TypeQuery */: return true; case 69 /* Identifier */: case 135 /* QualifiedName */: node = node.parent; continue; default: return false; } } ts.Debug.fail("should not get here"); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isInTypeQuery
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function hasInitializer(node) { return !!(node.initializer || ts.isBindingPattern(node.parent) && hasInitializer(node.parent.parent)); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
hasInitializer
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isAssignedInBinaryExpression(node) { if (node.operatorToken.kind >= 56 /* FirstAssignment */ && node.operatorToken.kind <= 68 /* LastAssignment */) { var n = node.left; while (n.kind === 172 /* ParenthesizedExpression */) { n = n.expression; } if (n.kind === 69 /* Identifier */ && getResolvedSymbol(n) === symbol) { return true; } } return ts.forEachChild(node, isAssignedIn); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isAssignedInBinaryExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isAssignedInVariableDeclaration(node) { if (!ts.isBindingPattern(node.name) && getSymbolOfNode(node) === symbol && hasInitializer(node)) { return true; } return ts.forEachChild(node, isAssignedIn); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isAssignedInVariableDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isAssignedIn(node) { switch (node.kind) { case 181 /* BinaryExpression */: return isAssignedInBinaryExpression(node); case 211 /* VariableDeclaration */: case 163 /* BindingElement */: return isAssignedInVariableDeclaration(node); case 161 /* ObjectBindingPattern */: case 162 /* ArrayBindingPattern */: case 164 /* ArrayLiteralExpression */: case 165 /* ObjectLiteralExpression */: case 166 /* PropertyAccessExpression */: case 167 /* ElementAccessExpression */: case 168 /* CallExpression */: case 169 /* NewExpression */: case 171 /* TypeAssertionExpression */: case 189 /* AsExpression */: case 172 /* ParenthesizedExpression */: case 179 /* PrefixUnaryExpression */: case 175 /* DeleteExpression */: case 178 /* AwaitExpression */: case 176 /* TypeOfExpression */: case 177 /* VoidExpression */: case 180 /* PostfixUnaryExpression */: case 184 /* YieldExpression */: case 182 /* ConditionalExpression */: case 185 /* SpreadElementExpression */: case 192 /* Block */: case 193 /* VariableStatement */: case 195 /* ExpressionStatement */: case 196 /* IfStatement */: case 197 /* DoStatement */: case 198 /* WhileStatement */: case 199 /* ForStatement */: case 200 /* ForInStatement */: case 201 /* ForOfStatement */: case 204 /* ReturnStatement */: case 205 /* WithStatement */: case 206 /* SwitchStatement */: case 241 /* CaseClause */: case 242 /* DefaultClause */: case 207 /* LabeledStatement */: case 208 /* ThrowStatement */: case 209 /* TryStatement */: case 244 /* CatchClause */: case 233 /* JsxElement */: case 234 /* JsxSelfClosingElement */: case 238 /* JsxAttribute */: case 239 /* JsxSpreadAttribute */: case 235 /* JsxOpeningElement */: case 240 /* JsxExpression */: return ts.forEachChild(node, isAssignedIn); } return false; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isAssignedIn
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getNarrowedTypeOfSymbol(symbol, node) { var type = getTypeOfSymbol(symbol); // Only narrow when symbol is variable of type any or an object, union, or type parameter type if (node && symbol.flags & 3 /* Variable */) { if (isTypeAny(type) || type.flags & (80896 /* ObjectType */ | 16384 /* Union */ | 512 /* TypeParameter */)) { loop: while (node.parent) { var child = node; node = node.parent; var narrowedType = type; switch (node.kind) { case 196 /* IfStatement */: // In a branch of an if statement, narrow based on controlling expression if (child !== node.expression) { narrowedType = narrowType(type, node.expression, /*assumeTrue*/ child === node.thenStatement); } break; case 182 /* ConditionalExpression */: // In a branch of a conditional expression, narrow based on controlling condition if (child !== node.condition) { narrowedType = narrowType(type, node.condition, /*assumeTrue*/ child === node.whenTrue); } break; case 181 /* BinaryExpression */: // In the right operand of an && or ||, narrow based on left operand if (child === node.right) { if (node.operatorToken.kind === 51 /* AmpersandAmpersandToken */) { narrowedType = narrowType(type, node.left, /*assumeTrue*/ true); } else if (node.operatorToken.kind === 52 /* BarBarToken */) { narrowedType = narrowType(type, node.left, /*assumeTrue*/ false); } } break; case 248 /* SourceFile */: case 218 /* ModuleDeclaration */: case 213 /* FunctionDeclaration */: case 143 /* MethodDeclaration */: case 142 /* MethodSignature */: case 145 /* GetAccessor */: case 146 /* SetAccessor */: case 144 /* Constructor */: // Stop at the first containing function or module declaration break loop; } // Use narrowed type if construct contains no assignments to variable if (narrowedType !== type) { if (isVariableAssignedWithin(symbol, node)) { break; } type = narrowedType; } } } } return type; function narrowTypeByEquality(type, expr, assumeTrue) { // Check that we have 'typeof <symbol>' on the left and string literal on the right if (expr.left.kind !== 176 /* TypeOfExpression */ || expr.right.kind !== 9 /* StringLiteral */) { return type; } var left = expr.left; var right = expr.right; if (left.expression.kind !== 69 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { return type; } var typeInfo = primitiveTypeInfo[right.text]; if (expr.operatorToken.kind === 33 /* ExclamationEqualsEqualsToken */) { assumeTrue = !assumeTrue; } if (assumeTrue) { // Assumed result is true. If check was not for a primitive type, remove all primitive types if (!typeInfo) { return removeTypesFromUnionType(type, /*typeKind*/ 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 16777216 /* ESSymbol */, /*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ false); } // Check was for a primitive type, return that primitive type if it is a subtype if (isTypeSubtypeOf(typeInfo.type, type)) { return typeInfo.type; } // Otherwise, remove all types that aren't of the primitive type kind. This can happen when the type is // union of enum types and other types. return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ false, /*allowEmptyUnionResult*/ false); } else { // Assumed result is false. If check was for a primitive type, remove that primitive type if (typeInfo) { return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ false); } // Otherwise we don't have enough information to do anything. return type; } } function narrowTypeByAnd(type, expr, assumeTrue) { if (assumeTrue) { // The assumed result is true, therefore we narrow assuming each operand to be true. return narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ true); } else { // The assumed result is false. This means either the first operand was false, or the first operand was true // and the second operand was false. We narrow with those assumptions and union the two resulting types. return getUnionType([ narrowType(type, expr.left, /*assumeTrue*/ false), narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ false) ]); } } function narrowTypeByOr(type, expr, assumeTrue) { if (assumeTrue) { // The assumed result is true. This means either the first operand was true, or the first operand was false // and the second operand was true. We narrow with those assumptions and union the two resulting types. return getUnionType([ narrowType(type, expr.left, /*assumeTrue*/ true), narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ true) ]); } else { // The assumed result is false, therefore we narrow assuming each operand to be false. return narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ false); } } function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left if (isTypeAny(type) || expr.left.kind !== 69 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property var rightType = checkExpression(expr.right); if (!isTypeSubtypeOf(rightType, globalFunctionType)) { return type; } var targetType; var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { // Target type is type of the prototype property var prototypePropertyType = getTypeOfSymbol(prototypeProperty); if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } if (!targetType) { // Target type is type of construct signature var constructSignatures; if (rightType.flags & 2048 /* Interface */) { constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } else if (rightType.flags & 65536 /* Anonymous */) { constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */); } if (constructSignatures && constructSignatures.length) { targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); } } if (targetType) { if (!assumeTrue) { if (type.flags & 16384 /* Union */) { return getUnionType(ts.filter(type.types, function (t) { return !isTypeSubtypeOf(t, targetType); })); } return type; } return getNarrowedType(type, targetType); } return type; } function getNarrowedType(originalType, narrowedTypeCandidate) { // If the current type is a union type, remove all constituents that aren't assignable to target. If that produces // 0 candidates, fall back to the assignability check if (originalType.flags & 16384 /* Union */) { var assignableConstituents = ts.filter(originalType.types, function (t) { return isTypeAssignableTo(t, narrowedTypeCandidate); }); if (assignableConstituents.length) { return getUnionType(assignableConstituents); } } if (isTypeAssignableTo(narrowedTypeCandidate, originalType)) { // Narrow to the target type if it's assignable to the current type return narrowedTypeCandidate; } return originalType; } function narrowTypeByTypePredicate(type, expr, assumeTrue) { if (type.flags & 1 /* Any */) { return type; } var signature = getResolvedSignature(expr); if (signature.typePredicate && expr.arguments[signature.typePredicate.parameterIndex] && getSymbolAtLocation(expr.arguments[signature.typePredicate.parameterIndex]) === symbol) { if (!assumeTrue) { if (type.flags & 16384 /* Union */) { return getUnionType(ts.filter(type.types, function (t) { return !isTypeSubtypeOf(t, signature.typePredicate.type); })); } return type; } return getNarrowedType(type, signature.typePredicate.type); } return type; } // Narrow the given type based on the given expression having the assumed boolean value. The returned type // will be a subtype or the same type as the argument. function narrowType(type, expr, assumeTrue) { switch (expr.kind) { case 168 /* CallExpression */: return narrowTypeByTypePredicate(type, expr, assumeTrue); case 172 /* ParenthesizedExpression */: return narrowType(type, expr.expression, assumeTrue); case 181 /* BinaryExpression */: var operator = expr.operatorToken.kind; if (operator === 32 /* EqualsEqualsEqualsToken */ || operator === 33 /* ExclamationEqualsEqualsToken */) { return narrowTypeByEquality(type, expr, assumeTrue); } else if (operator === 51 /* AmpersandAmpersandToken */) { return narrowTypeByAnd(type, expr, assumeTrue); } else if (operator === 52 /* BarBarToken */) { return narrowTypeByOr(type, expr, assumeTrue); } else if (operator === 91 /* InstanceOfKeyword */) { return narrowTypeByInstanceof(type, expr, assumeTrue); } break; case 179 /* PrefixUnaryExpression */: if (expr.operator === 49 /* ExclamationToken */) { return narrowType(type, expr.operand, !assumeTrue); } break; } return type; } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getNarrowedTypeOfSymbol
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function narrowTypeByEquality(type, expr, assumeTrue) { // Check that we have 'typeof <symbol>' on the left and string literal on the right if (expr.left.kind !== 176 /* TypeOfExpression */ || expr.right.kind !== 9 /* StringLiteral */) { return type; } var left = expr.left; var right = expr.right; if (left.expression.kind !== 69 /* Identifier */ || getResolvedSymbol(left.expression) !== symbol) { return type; } var typeInfo = primitiveTypeInfo[right.text]; if (expr.operatorToken.kind === 33 /* ExclamationEqualsEqualsToken */) { assumeTrue = !assumeTrue; } if (assumeTrue) { // Assumed result is true. If check was not for a primitive type, remove all primitive types if (!typeInfo) { return removeTypesFromUnionType(type, /*typeKind*/ 258 /* StringLike */ | 132 /* NumberLike */ | 8 /* Boolean */ | 16777216 /* ESSymbol */, /*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ false); } // Check was for a primitive type, return that primitive type if it is a subtype if (isTypeSubtypeOf(typeInfo.type, type)) { return typeInfo.type; } // Otherwise, remove all types that aren't of the primitive type kind. This can happen when the type is // union of enum types and other types. return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ false, /*allowEmptyUnionResult*/ false); } else { // Assumed result is false. If check was for a primitive type, remove that primitive type if (typeInfo) { return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ true, /*allowEmptyUnionResult*/ false); } // Otherwise we don't have enough information to do anything. return type; } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
narrowTypeByEquality
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function narrowTypeByAnd(type, expr, assumeTrue) { if (assumeTrue) { // The assumed result is true, therefore we narrow assuming each operand to be true. return narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ true); } else { // The assumed result is false. This means either the first operand was false, or the first operand was true // and the second operand was false. We narrow with those assumptions and union the two resulting types. return getUnionType([ narrowType(type, expr.left, /*assumeTrue*/ false), narrowType(narrowType(type, expr.left, /*assumeTrue*/ true), expr.right, /*assumeTrue*/ false) ]); } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
narrowTypeByAnd
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function narrowTypeByOr(type, expr, assumeTrue) { if (assumeTrue) { // The assumed result is true. This means either the first operand was true, or the first operand was false // and the second operand was true. We narrow with those assumptions and union the two resulting types. return getUnionType([ narrowType(type, expr.left, /*assumeTrue*/ true), narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ true) ]); } else { // The assumed result is false, therefore we narrow assuming each operand to be false. return narrowType(narrowType(type, expr.left, /*assumeTrue*/ false), expr.right, /*assumeTrue*/ false); } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
narrowTypeByOr
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function narrowTypeByInstanceof(type, expr, assumeTrue) { // Check that type is not any, assumed result is true, and we have variable symbol on the left if (isTypeAny(type) || expr.left.kind !== 69 /* Identifier */ || getResolvedSymbol(expr.left) !== symbol) { return type; } // Check that right operand is a function type with a prototype property var rightType = checkExpression(expr.right); if (!isTypeSubtypeOf(rightType, globalFunctionType)) { return type; } var targetType; var prototypeProperty = getPropertyOfType(rightType, "prototype"); if (prototypeProperty) { // Target type is type of the prototype property var prototypePropertyType = getTypeOfSymbol(prototypeProperty); if (!isTypeAny(prototypePropertyType)) { targetType = prototypePropertyType; } } if (!targetType) { // Target type is type of construct signature var constructSignatures; if (rightType.flags & 2048 /* Interface */) { constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures; } else if (rightType.flags & 65536 /* Anonymous */) { constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */); } if (constructSignatures && constructSignatures.length) { targetType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); })); } } if (targetType) { if (!assumeTrue) { if (type.flags & 16384 /* Union */) { return getUnionType(ts.filter(type.types, function (t) { return !isTypeSubtypeOf(t, targetType); })); } return type; } return getNarrowedType(type, targetType); } return type; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
narrowTypeByInstanceof
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getNarrowedType(originalType, narrowedTypeCandidate) { // If the current type is a union type, remove all constituents that aren't assignable to target. If that produces // 0 candidates, fall back to the assignability check if (originalType.flags & 16384 /* Union */) { var assignableConstituents = ts.filter(originalType.types, function (t) { return isTypeAssignableTo(t, narrowedTypeCandidate); }); if (assignableConstituents.length) { return getUnionType(assignableConstituents); } } if (isTypeAssignableTo(narrowedTypeCandidate, originalType)) { // Narrow to the target type if it's assignable to the current type return narrowedTypeCandidate; } return originalType; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getNarrowedType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function narrowTypeByTypePredicate(type, expr, assumeTrue) { if (type.flags & 1 /* Any */) { return type; } var signature = getResolvedSignature(expr); if (signature.typePredicate && expr.arguments[signature.typePredicate.parameterIndex] && getSymbolAtLocation(expr.arguments[signature.typePredicate.parameterIndex]) === symbol) { if (!assumeTrue) { if (type.flags & 16384 /* Union */) { return getUnionType(ts.filter(type.types, function (t) { return !isTypeSubtypeOf(t, signature.typePredicate.type); })); } return type; } return getNarrowedType(type, signature.typePredicate.type); } return type; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
narrowTypeByTypePredicate
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkIdentifier(node) { var symbol = getResolvedSymbol(node); // As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects. // Although in down-level emit of arrow function, we emit it using function expression which means that // arguments objects will be bound to the inner object; emitting arrow function natively in ES6, arguments objects // will be bound to non-arrow function that contain this arrow function. This results in inconsistent behavior. // To avoid that we will give an error to users if they use arguments objects in arrow function so that they // can explicitly bound arguments objects if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); if (container.kind === 174 /* ArrowFunction */) { if (languageVersion < 2 /* ES6 */) { error(node, ts.Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } } if (node.parserContextFlags & 8 /* Await */) { getNodeLinks(container).flags |= 4096 /* CaptureArguments */; getNodeLinks(node).flags |= 2048 /* LexicalArguments */; } } if (symbol.flags & 8388608 /* Alias */ && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { markAliasSymbolAsReferenced(symbol); } checkCollisionWithCapturedSuperVariable(node, node); checkCollisionWithCapturedThisVariable(node, node); checkBlockScopedBindingCapturedInLoop(node, symbol); return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
checkIdentifier
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInsideFunction(node, threshold) { var current = node; while (current && current !== threshold) { if (ts.isFunctionLike(current)) { return true; } current = current.parent; } return false; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isInsideFunction
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkBlockScopedBindingCapturedInLoop(node, symbol) { if (languageVersion >= 2 /* ES6 */ || (symbol.flags & (2 /* BlockScopedVariable */ | 32 /* Class */)) === 0 || symbol.valueDeclaration.parent.kind === 244 /* CatchClause */) { return; } // 1. walk from the use site up to the declaration and check // if there is anything function like between declaration and use-site (is binding/class is captured in function). // 2. walk from the declaration up to the boundary of lexical environment and check // if there is an iteration statement in between declaration and boundary (is binding/class declared inside iteration statement) var container; if (symbol.flags & 32 /* Class */) { // get parent of class declaration container = getClassLikeDeclarationOfSymbol(symbol).parent; } else { // nesting structure: // (variable declaration or binding element) -> variable declaration list -> container container = symbol.valueDeclaration; while (container.kind !== 212 /* VariableDeclarationList */) { container = container.parent; } // get the parent of variable declaration list container = container.parent; if (container.kind === 193 /* VariableStatement */) { // if parent is variable statement - get its parent container = container.parent; } } var inFunction = isInsideFunction(node.parent, container); var current = container; while (current && !ts.nodeStartsNewLexicalEnvironment(current)) { if (ts.isIterationStatement(current, /*lookInLabeledStatements*/ false)) { if (inFunction) { getNodeLinks(current).flags |= 65536 /* LoopWithBlockScopedBindingCapturedInFunction */; } // mark value declaration so during emit they can have a special handling getNodeLinks(symbol.valueDeclaration).flags |= 16384 /* BlockScopedBindingInLoop */; break; } current = current.parent; } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
checkBlockScopedBindingCapturedInLoop
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function captureLexicalThis(node, container) { getNodeLinks(node).flags |= 2 /* LexicalThis */; if (container.kind === 141 /* PropertyDeclaration */ || container.kind === 144 /* Constructor */) { var classNode = container.parent; getNodeLinks(classNode).flags |= 4 /* CaptureThis */; } else { getNodeLinks(container).flags |= 4 /* CaptureThis */; } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
captureLexicalThis
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkThisExpression(node) { // Stop at the first arrow function so that we can // tell whether 'this' needs to be captured. var container = ts.getThisContainer(node, /* includeArrowFunctions */ true); var needToCaptureLexicalThis = false; // Now skip arrow functions to get the "real" owner of 'this'. if (container.kind === 174 /* ArrowFunction */) { container = ts.getThisContainer(container, /* includeArrowFunctions */ false); // When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code needToCaptureLexicalThis = (languageVersion < 2 /* ES6 */); } switch (container.kind) { case 218 /* ModuleDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; case 217 /* EnumDeclaration */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location); // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks break; case 144 /* Constructor */: if (isInConstructorArgumentInitializer(node, container)) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_constructor_arguments); } break; case 141 /* PropertyDeclaration */: case 140 /* PropertySignature */: if (container.flags & 64 /* Static */) { error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); } break; case 136 /* ComputedPropertyName */: error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; } if (needToCaptureLexicalThis) { captureLexicalThis(node, container); } if (ts.isClassLike(container.parent)) { var symbol = getSymbolOfNode(container.parent); return container.flags & 64 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol).thisType; } return anyType; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
checkThisExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInConstructorArgumentInitializer(node, constructorDecl) { for (var n = node; n && n !== constructorDecl; n = n.parent) { if (n.kind === 138 /* Parameter */) { return true; } } return false; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isInConstructorArgumentInitializer
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkSuperExpression(node) { var isCallExpression = node.parent.kind === 168 /* CallExpression */ && node.parent.expression === node; var classDeclaration = ts.getContainingClass(node); var classType = classDeclaration && getDeclaredTypeOfSymbol(getSymbolOfNode(classDeclaration)); var baseClassType = classType && getBaseTypes(classType)[0]; var container = ts.getSuperContainer(node, /*includeFunctions*/ true); var needToCaptureLexicalThis = false; if (!isCallExpression) { // adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting while (container && container.kind === 174 /* ArrowFunction */) { container = ts.getSuperContainer(container, /*includeFunctions*/ true); needToCaptureLexicalThis = languageVersion < 2 /* ES6 */; } } var canUseSuperExpression = isLegalUsageOfSuperExpression(container); var nodeCheckFlag = 0; // always set NodeCheckFlags for 'super' expression node if (canUseSuperExpression) { if ((container.flags & 64 /* Static */) || isCallExpression) { nodeCheckFlag = 512 /* SuperStatic */; } else { nodeCheckFlag = 256 /* SuperInstance */; } getNodeLinks(node).flags |= nodeCheckFlag; if (needToCaptureLexicalThis) { // call expressions are allowed only in constructors so they should always capture correct 'this' // super property access expressions can also appear in arrow functions - // in this case they should also use correct lexical this captureLexicalThis(node.parent, container); } } if (!baseClassType) { if (!classDeclaration || !ts.getClassExtendsHeritageClauseElement(classDeclaration)) { error(node, ts.Diagnostics.super_can_only_be_referenced_in_a_derived_class); } return unknownType; } if (!canUseSuperExpression) { if (container && container.kind === 136 /* ComputedPropertyName */) { error(node, ts.Diagnostics.super_cannot_be_referenced_in_a_computed_property_name); } else if (isCallExpression) { error(node, ts.Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors); } else { error(node, ts.Diagnostics.super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class); } return unknownType; } if (container.kind === 144 /* Constructor */ && isInConstructorArgumentInitializer(node, container)) { // issue custom error message for super property access in constructor arguments (to be aligned with old compiler) error(node, ts.Diagnostics.super_cannot_be_referenced_in_constructor_arguments); return unknownType; } return nodeCheckFlag === 512 /* SuperStatic */ ? getBaseConstructorTypeOfClass(classType) : baseClassType; function isLegalUsageOfSuperExpression(container) { if (!container) { return false; } if (isCallExpression) { // TS 1.0 SPEC (April 2014): 4.8.1 // Super calls are only permitted in constructors of derived classes return container.kind === 144 /* Constructor */; } else { // TS 1.0 SPEC (April 2014) // 'super' property access is allowed // - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance // - In a static member function or static member accessor // topmost container must be something that is directly nested in the class declaration if (container && ts.isClassLike(container.parent)) { if (container.flags & 64 /* Static */) { return container.kind === 143 /* MethodDeclaration */ || container.kind === 142 /* MethodSignature */ || container.kind === 145 /* GetAccessor */ || container.kind === 146 /* SetAccessor */; } else { return container.kind === 143 /* MethodDeclaration */ || container.kind === 142 /* MethodSignature */ || container.kind === 145 /* GetAccessor */ || container.kind === 146 /* SetAccessor */ || container.kind === 141 /* PropertyDeclaration */ || container.kind === 140 /* PropertySignature */ || container.kind === 144 /* Constructor */; } } } return false; } }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
checkSuperExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isLegalUsageOfSuperExpression(container) { if (!container) { return false; } if (isCallExpression) { // TS 1.0 SPEC (April 2014): 4.8.1 // Super calls are only permitted in constructors of derived classes return container.kind === 144 /* Constructor */; } else { // TS 1.0 SPEC (April 2014) // 'super' property access is allowed // - In a constructor, instance member function, instance member accessor, or instance member variable initializer where this references a derived class instance // - In a static member function or static member accessor // topmost container must be something that is directly nested in the class declaration if (container && ts.isClassLike(container.parent)) { if (container.flags & 64 /* Static */) { return container.kind === 143 /* MethodDeclaration */ || container.kind === 142 /* MethodSignature */ || container.kind === 145 /* GetAccessor */ || container.kind === 146 /* SetAccessor */; } else { return container.kind === 143 /* MethodDeclaration */ || container.kind === 142 /* MethodSignature */ || container.kind === 145 /* GetAccessor */ || container.kind === 146 /* SetAccessor */ || container.kind === 141 /* PropertyDeclaration */ || container.kind === 140 /* PropertySignature */ || container.kind === 144 /* Constructor */; } } } return false; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isLegalUsageOfSuperExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForReturnExpression(node) { var func = ts.getContainingFunction(node); if (func && !func.asteriskToken) { return getContextualReturnType(func); } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForReturnExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForYieldOperand(node) { var func = ts.getContainingFunction(node); if (func) { var contextualReturnType = getContextualReturnType(func); if (contextualReturnType) { return node.asteriskToken ? contextualReturnType : getElementTypeOfIterableIterator(contextualReturnType); } } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForYieldOperand
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInParameterInitializerBeforeContainingFunction(node) { while (node.parent && !ts.isFunctionLike(node.parent)) { if (node.parent.kind === 138 /* Parameter */ && node.parent.initializer === node) { return true; } node = node.parent; } return false; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
isInParameterInitializerBeforeContainingFunction
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualReturnType(functionDecl) { // If the containing function has a return type annotation, is a constructor, or is a get accessor whose // corresponding set accessor has a type annotation, return statements in the function are contextually typed if (functionDecl.type || functionDecl.kind === 144 /* Constructor */ || functionDecl.kind === 145 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 146 /* SetAccessor */))) { return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); } // Otherwise, if the containing function is contextually typed by a function type with exactly one call signature // and that call signature is non-generic, return statements are contextually typed by the return type of the signature var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); if (signature) { return getReturnTypeOfSignature(signature); } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualReturnType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForArgument(callTarget, arg) { var args = getEffectiveCallArguments(callTarget); var argIndex = ts.indexOf(args, arg); if (argIndex >= 0) { var signature = getResolvedSignature(callTarget); return getTypeAtPosition(signature, argIndex); } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForArgument
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForSubstitutionExpression(template, substitutionExpression) { if (template.parent.kind === 170 /* TaggedTemplateExpression */) { return getContextualTypeForArgument(template.parent, substitutionExpression); } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForSubstitutionExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForBinaryOperand(node) { var binaryExpression = node.parent; var operator = binaryExpression.operatorToken.kind; if (operator >= 56 /* FirstAssignment */ && operator <= 68 /* LastAssignment */) { // In an assignment expression, the right operand is contextually typed by the type of the left operand. if (node === binaryExpression.right) { return checkExpression(binaryExpression.left); } } else if (operator === 52 /* BarBarToken */) { // When an || expression has a contextual type, the operands are contextually typed by that type. When an || // expression has no contextual type, the right operand is contextually typed by the type of the left operand. var type = getContextualType(binaryExpression); if (!type && node === binaryExpression.right) { type = checkExpression(binaryExpression.left); } return type; } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForBinaryOperand
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function applyToContextualType(type, mapper) { if (!(type.flags & 16384 /* Union */)) { return mapper(type); } var types = type.types; var mappedType; var mappedTypes; for (var _i = 0, types_7 = types; _i < types_7.length; _i++) { var current = types_7[_i]; var t = mapper(current); if (t) { if (!mappedType) { mappedType = t; } else if (!mappedTypes) { mappedTypes = [mappedType, t]; } else { mappedTypes.push(t); } } } return mappedTypes ? getUnionType(mappedTypes) : mappedType; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
applyToContextualType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getTypeOfPropertyOfContextualType(type, name) { return applyToContextualType(type, function (t) { var prop = t.flags & 130048 /* StructuredType */ ? getPropertyOfType(t, name) : undefined; return prop ? getTypeOfSymbol(prop) : undefined; }); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getTypeOfPropertyOfContextualType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getIndexTypeOfContextualType(type, kind) { return applyToContextualType(type, function (t) { return getIndexTypeOfStructuredType(t, kind); }); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getIndexTypeOfContextualType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function contextualTypeIsStringLiteralType(type) { return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, isStringLiteralType) : isStringLiteralType(type)); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
contextualTypeIsStringLiteralType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function contextualTypeIsTupleLikeType(type) { return !!(type.flags & 16384 /* Union */ ? ts.forEach(type.types, isTupleLikeType) : isTupleLikeType(type)); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
contextualTypeIsTupleLikeType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForObjectLiteralElement(element) { var objectLiteral = element.parent; var type = getApparentTypeOfContextualType(objectLiteral); if (type) { if (!ts.hasDynamicName(element)) { // For a (non-symbol) computed property, there is no reason to look up the name // in the type. It will just be "__computed", which does not appear in any // SymbolTable. var symbolName = getSymbolOfNode(element).name; var propertyType = getTypeOfPropertyOfContextualType(type, symbolName); if (propertyType) { return propertyType; } } return isNumericName(element.name) && getIndexTypeOfContextualType(type, 1 /* Number */) || getIndexTypeOfContextualType(type, 0 /* String */); } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForObjectLiteralElement
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForElementExpression(node) { var arrayLiteral = node.parent; var type = getApparentTypeOfContextualType(arrayLiteral); if (type) { var index = ts.indexOf(arrayLiteral.elements, node); return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1 /* Number */) || (languageVersion >= 2 /* ES6 */ ? getElementTypeOfIterable(type, /*errorNode*/ undefined) : undefined); } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForElementExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualTypeForJsxExpression(expr) { // Contextual type only applies to JSX expressions that are in attribute assignments (not in 'Children' positions) if (expr.parent.kind === 238 /* JsxAttribute */) { var attrib = expr.parent; var attrsType = getJsxElementAttributesType(attrib.parent); if (!attrsType || isTypeAny(attrsType)) { return undefined; } else { return getTypeOfPropertyOfType(attrsType, attrib.name.text); } } if (expr.kind === 239 /* JsxSpreadAttribute */) { return getJsxElementAttributesType(expr.parent); } return undefined; }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getContextualTypeForJsxExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getApparentTypeOfContextualType(node) { var type = getContextualType(node); return type && getApparentType(type); }
Reports implicit any errors that occur as a result of widening 'null' and 'undefined' to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to getWidenedType. But in some cases getWidenedType is called without reporting errors (type argument inference is an example). The return value indicates whether an error was in fact reported. The particular circumstances are on a best effort basis. Currently, if the null or undefined that causes widening is inside an object literal property (arbitrarily deeply), this function reports an error. If no error is reported, reportImplicitAnyError is a suitable fallback to report a general error.
getApparentTypeOfContextualType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualType(node) { if (isInsideWithStatementBody(node)) { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; } if (node.contextualType) { return node.contextualType; } var parent = node.parent; switch (parent.kind) { case 211 /* VariableDeclaration */: case 138 /* Parameter */: case 141 /* PropertyDeclaration */: case 140 /* PropertySignature */: case 163 /* BindingElement */: return getContextualTypeForInitializerExpression(node); case 174 /* ArrowFunction */: case 204 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); case 184 /* YieldExpression */: return getContextualTypeForYieldOperand(parent); case 168 /* CallExpression */: case 169 /* NewExpression */: return getContextualTypeForArgument(parent, node); case 171 /* TypeAssertionExpression */: case 189 /* AsExpression */: return getTypeFromTypeNode(parent.type); case 181 /* BinaryExpression */: return getContextualTypeForBinaryOperand(node); case 245 /* PropertyAssignment */: return getContextualTypeForObjectLiteralElement(parent); case 164 /* ArrayLiteralExpression */: return getContextualTypeForElementExpression(node); case 182 /* ConditionalExpression */: return getContextualTypeForConditionalOperand(node); case 190 /* TemplateSpan */: ts.Debug.assert(parent.parent.kind === 183 /* TemplateExpression */); return getContextualTypeForSubstitutionExpression(parent.parent, node); case 172 /* ParenthesizedExpression */: return getContextualType(parent); case 240 /* JsxExpression */: case 239 /* JsxSpreadAttribute */: return getContextualTypeForJsxExpression(parent); } return undefined; }
Woah! Do you really want to use this function? Unless you're trying to get the *non-apparent* type for a value-literal type or you're authoring relevant portions of this algorithm, you probably meant to use 'getApparentTypeOfContextualType'. Otherwise this may not be very useful. In cases where you *are* working on this function, you should understand when it is appropriate to use 'getContextualType' and 'getApparentTypeOfContetxualType'. - Use 'getContextualType' when you are simply going to propagate the result to the expression. - Use 'getApparentTypeOfContextualType' when you're going to need the members of the type. @param node the expression whose contextual type will be returned. @returns the contextual type of an expression.
getContextualType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isFunctionExpressionOrArrowFunction(node) { return node.kind === 173 /* FunctionExpression */ || node.kind === 174 /* ArrowFunction */; }
Woah! Do you really want to use this function? Unless you're trying to get the *non-apparent* type for a value-literal type or you're authoring relevant portions of this algorithm, you probably meant to use 'getApparentTypeOfContextualType'. Otherwise this may not be very useful. In cases where you *are* working on this function, you should understand when it is appropriate to use 'getContextualType' and 'getApparentTypeOfContetxualType'. - Use 'getContextualType' when you are simply going to propagate the result to the expression. - Use 'getApparentTypeOfContextualType' when you're going to need the members of the type. @param node the expression whose contextual type will be returned. @returns the contextual type of an expression.
isFunctionExpressionOrArrowFunction
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualSignatureForFunctionLikeDeclaration(node) { // Only function expressions, arrow functions, and object literal methods are contextually typed. return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node) ? getContextualSignature(node) : undefined; }
Woah! Do you really want to use this function? Unless you're trying to get the *non-apparent* type for a value-literal type or you're authoring relevant portions of this algorithm, you probably meant to use 'getApparentTypeOfContextualType'. Otherwise this may not be very useful. In cases where you *are* working on this function, you should understand when it is appropriate to use 'getContextualType' and 'getApparentTypeOfContetxualType'. - Use 'getContextualType' when you are simply going to propagate the result to the expression. - Use 'getApparentTypeOfContextualType' when you're going to need the members of the type. @param node the expression whose contextual type will be returned. @returns the contextual type of an expression.
getContextualSignatureForFunctionLikeDeclaration
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getContextualSignature(node) { ts.Debug.assert(node.kind !== 143 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node)); var type = ts.isObjectLiteralMethod(node) ? getContextualTypeForObjectLiteralMethod(node) : getApparentTypeOfContextualType(node); if (!type) { return undefined; } if (!(type.flags & 16384 /* Union */)) { return getNonGenericSignature(type); } var signatureList; var types = type.types; for (var _i = 0, types_8 = types; _i < types_8.length; _i++) { var current = types_8[_i]; var signature = getNonGenericSignature(current); if (signature) { if (!signatureList) { // This signature will contribute to contextual union signature signatureList = [signature]; } else if (!compareSignatures(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypes)) { // Signatures aren't identical, do not use return undefined; } else { // Use this signature for contextual union signature signatureList.push(signature); } } } // Result is union of signatures collected (return type is union of return types of this signature set) var result; if (signatureList) { result = cloneSignature(signatureList[0]); // Clear resolved return type we possibly got from cloneSignature result.resolvedReturnType = undefined; result.unionSignatures = signatureList; } return result; }
Woah! Do you really want to use this function? Unless you're trying to get the *non-apparent* type for a value-literal type or you're authoring relevant portions of this algorithm, you probably meant to use 'getApparentTypeOfContextualType'. Otherwise this may not be very useful. In cases where you *are* working on this function, you should understand when it is appropriate to use 'getContextualType' and 'getApparentTypeOfContetxualType'. - Use 'getContextualType' when you are simply going to propagate the result to the expression. - Use 'getApparentTypeOfContextualType' when you're going to need the members of the type. @param node the expression whose contextual type will be returned. @returns the contextual type of an expression.
getContextualSignature
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isInferentialContext(mapper) { return mapper && mapper.context; }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
isInferentialContext
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkSpreadElementExpression(node, contextualMapper) { // It is usually not safe to call checkExpressionCached if we can be contextually typing. // You can tell that we are contextually typing because of the contextualMapper parameter. // While it is true that a spread element can have a contextual type, it does not do anything // with this type. It is neither affected by it, nor does it propagate it to its operand. // So the fact that contextualMapper is passed is not important, because the operand of a spread // element is not contextually typed. var arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper); return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false); }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
checkSpreadElementExpression
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function hasDefaultValue(node) { return (node.kind === 163 /* BindingElement */ && !!node.initializer) || (node.kind === 181 /* BinaryExpression */ && node.operatorToken.kind === 56 /* EqualsToken */); }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
hasDefaultValue
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkArrayLiteral(node, contextualMapper) { var elements = node.elements; var hasSpreadElement = false; var elementTypes = []; var inDestructuringPattern = isAssignmentTarget(node); for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) { var e = elements_1[_i]; if (inDestructuringPattern && e.kind === 185 /* SpreadElementExpression */) { // Given the following situation: // var c: {}; // [...c] = ["", 0]; // // c is represented in the tree as a spread element in an array literal. // But c really functions as a rest element, and its purpose is to provide // a contextual type for the right hand side of the assignment. Therefore, // instead of calling checkExpression on "...c", which will give an error // if c is not iterable/array-like, we need to act as if we are trying to // get the contextual element type from it. So we do something similar to // getContextualTypeForElementExpression, which will crucially not error // if there is no index type / iterated type. var restArrayType = checkExpression(e.expression, contextualMapper); var restElementType = getIndexTypeOfType(restArrayType, 1 /* Number */) || (languageVersion >= 2 /* ES6 */ ? getElementTypeOfIterable(restArrayType, /*errorNode*/ undefined) : undefined); if (restElementType) { elementTypes.push(restElementType); } } else { var type = checkExpression(e, contextualMapper); elementTypes.push(type); } hasSpreadElement = hasSpreadElement || e.kind === 185 /* SpreadElementExpression */; } if (!hasSpreadElement) { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such // that we get the same behavior for "var [x, y] = []" and "[x, y] = []". if (inDestructuringPattern && elementTypes.length) { var type = createNewTupleType(elementTypes); type.pattern = node; return type; } var contextualType = getApparentTypeOfContextualType(node); if (contextualType && contextualTypeIsTupleLikeType(contextualType)) { var pattern = contextualType.pattern; // If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting // tuple type with the corresponding binding or assignment element types to make the lengths equal. if (pattern && (pattern.kind === 162 /* ArrayBindingPattern */ || pattern.kind === 164 /* ArrayLiteralExpression */)) { var patternElements = pattern.elements; for (var i = elementTypes.length; i < patternElements.length; i++) { var patternElement = patternElements[i]; if (hasDefaultValue(patternElement)) { elementTypes.push(contextualType.elementTypes[i]); } else { if (patternElement.kind !== 187 /* OmittedExpression */) { error(patternElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); } elementTypes.push(unknownType); } } } if (elementTypes.length) { return createTupleType(elementTypes); } } } return createArrayType(elementTypes.length ? getUnionType(elementTypes) : undefinedType); }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
checkArrayLiteral
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isNumericName(name) { return name.kind === 136 /* ComputedPropertyName */ ? isNumericComputedName(name) : isNumericLiteralName(name.text); }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
isNumericName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isNumericComputedName(name) { // It seems odd to consider an expression of type Any to result in a numeric name, // but this behavior is consistent with checkIndexedAccess return isTypeAnyOrAllConstituentTypesHaveKind(checkComputedPropertyName(name), 132 /* NumberLike */); }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
isNumericComputedName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isTypeAnyOrAllConstituentTypesHaveKind(type, kind) { return isTypeAny(type) || allConstituentTypesHaveKind(type, kind); }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
isTypeAnyOrAllConstituentTypesHaveKind
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function isNumericLiteralName(name) { // The intent of numeric names is that // - they are names with text in a numeric form, and that // - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit', // acquired by applying the abstract 'ToNumber' operation on the name's text. // // The subtlety is in the latter portion, as we cannot reliably say that anything that looks like a numeric literal is a numeric name. // In fact, it is the case that the text of the name must be equal to 'ToString(numLit)' for this to hold. // // Consider the property name '"0xF00D"'. When one indexes with '0xF00D', they are actually indexing with the value of 'ToString(0xF00D)' // according to the ECMAScript specification, so it is actually as if the user indexed with the string '"61453"'. // Thus, the text of all numeric literals equivalent to '61543' such as '0xF00D', '0xf00D', '0170015', etc. are not valid numeric names // because their 'ToString' representation is not equal to their original text. // This is motivated by ECMA-262 sections 9.3.1, 9.8.1, 11.1.5, and 11.2.1. // // Here, we test whether 'ToString(ToNumber(name))' is exactly equal to 'name'. // The '+' prefix operator is equivalent here to applying the abstract ToNumber operation. // Applying the 'toString()' method on a number gives us the abstract ToString operation on a number. // // Note that this accepts the values 'Infinity', '-Infinity', and 'NaN', and that this is intentional. // This is desired behavior, because when indexing with them as numeric entities, you are indexing // with the strings '"Infinity"', '"-Infinity"', and '"NaN"' respectively. return (+name).toString() === name; }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
isNumericLiteralName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkComputedPropertyName(node) { var links = getNodeLinks(node.expression); if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). if (!isTypeAnyOrAllConstituentTypesHaveKind(links.resolvedType, 132 /* NumberLike */ | 258 /* StringLike */ | 16777216 /* ESSymbol */)) { error(node, ts.Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { checkThatExpressionIsProperSymbolReference(node.expression, links.resolvedType, /*reportError*/ true); } } return links.resolvedType; }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
checkComputedPropertyName
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function checkObjectLiteral(node, contextualMapper) { var inDestructuringPattern = isAssignmentTarget(node); // Grammar checking checkGrammarObjectLiteralExpression(node, inDestructuringPattern); var propertiesTable = {}; var propertiesArray = []; var contextualType = getApparentTypeOfContextualType(node); var contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === 161 /* ObjectBindingPattern */ || contextualType.pattern.kind === 165 /* ObjectLiteralExpression */); var typeFlags = 0; var patternWithComputedProperties = false; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var memberDecl = _a[_i]; var member = memberDecl.symbol; if (memberDecl.kind === 245 /* PropertyAssignment */ || memberDecl.kind === 246 /* ShorthandPropertyAssignment */ || ts.isObjectLiteralMethod(memberDecl)) { var type = void 0; if (memberDecl.kind === 245 /* PropertyAssignment */) { type = checkPropertyAssignment(memberDecl, contextualMapper); } else if (memberDecl.kind === 143 /* MethodDeclaration */) { type = checkObjectLiteralMethod(memberDecl, contextualMapper); } else { ts.Debug.assert(memberDecl.kind === 246 /* ShorthandPropertyAssignment */); type = checkExpression(memberDecl.name, contextualMapper); } typeFlags |= type.flags; var prop = createSymbol(4 /* Property */ | 67108864 /* Transient */ | member.flags, member.name); if (inDestructuringPattern) { // If object literal is an assignment pattern and if the assignment pattern specifies a default value // for the property, make the property optional. var isOptional = (memberDecl.kind === 245 /* PropertyAssignment */ && hasDefaultValue(memberDecl.initializer)) || (memberDecl.kind === 246 /* ShorthandPropertyAssignment */ && memberDecl.objectAssignmentInitializer); if (isOptional) { prop.flags |= 536870912 /* Optional */; } if (ts.hasDynamicName(memberDecl)) { patternWithComputedProperties = true; } } else if (contextualTypeHasPattern && !(contextualType.flags & 67108864 /* ObjectLiteralPatternWithComputedProperties */)) { // If object literal is contextually typed by the implied type of a binding pattern, and if the // binding pattern specifies a default value for the property, make the property optional. var impliedProp = getPropertyOfType(contextualType, member.name); if (impliedProp) { prop.flags |= impliedProp.flags & 536870912 /* Optional */; } else if (!compilerOptions.suppressExcessPropertyErrors) { error(memberDecl.name, ts.Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(member), typeToString(contextualType)); } } prop.declarations = member.declarations; prop.parent = member.parent; if (member.valueDeclaration) { prop.valueDeclaration = member.valueDeclaration; } prop.type = type; prop.target = member; member = prop; } else { // TypeScript 1.0 spec (April 2014) // A get accessor declaration is processed in the same manner as // an ordinary function declaration(section 6.1) with no parameters. // A set accessor declaration is processed in the same manner // as an ordinary function declaration with a single parameter and a Void return type. ts.Debug.assert(memberDecl.kind === 145 /* GetAccessor */ || memberDecl.kind === 146 /* SetAccessor */); checkAccessorDeclaration(memberDecl); } if (!ts.hasDynamicName(memberDecl)) { propertiesTable[member.name] = member; } propertiesArray.push(member); } // If object literal is contextually typed by the implied type of a binding pattern, augment the result // type with those properties for which the binding pattern specifies a default value. if (contextualTypeHasPattern) { for (var _b = 0, _c = getPropertiesOfType(contextualType); _b < _c.length; _b++) { var prop = _c[_b]; if (!ts.hasProperty(propertiesTable, prop.name)) { if (!(prop.flags & 536870912 /* Optional */)) { error(prop.valueDeclaration || prop.bindingElement, ts.Diagnostics.Initializer_provides_no_value_for_this_binding_element_and_the_binding_element_has_no_default_value); } propertiesTable[prop.name] = prop; propertiesArray.push(prop); } } } var stringIndexType = getIndexType(0 /* String */); var numberIndexType = getIndexType(1 /* Number */); var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType); var freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : 1048576 /* FreshObjectLiteral */; result.flags |= 524288 /* ObjectLiteral */ | 4194304 /* ContainsObjectLiteral */ | freshObjectLiteralFlag | (typeFlags & 14680064 /* PropagatingFlags */) | (patternWithComputedProperties ? 67108864 /* ObjectLiteralPatternWithComputedProperties */ : 0); if (inDestructuringPattern) { result.pattern = node; } return result; function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { var propTypes = []; for (var i = 0; i < propertiesArray.length; i++) { var propertyDecl = node.properties[i]; if (kind === 0 /* String */ || isNumericName(propertyDecl.name)) { // Do not call getSymbolOfNode(propertyDecl), as that will get the // original symbol for the node. We actually want to get the symbol // created by checkObjectLiteral, since that will be appropriately // contextually typed and resolved. var type = getTypeOfSymbol(propertiesArray[i]); if (!ts.contains(propTypes, type)) { propTypes.push(type); } } } var result_1 = propTypes.length ? getUnionType(propTypes) : undefinedType; typeFlags |= result_1.flags; return result_1; } return undefined; } }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
checkObjectLiteral
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT
function getIndexType(kind) { if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) { var propTypes = []; for (var i = 0; i < propertiesArray.length; i++) { var propertyDecl = node.properties[i]; if (kind === 0 /* String */ || isNumericName(propertyDecl.name)) { // Do not call getSymbolOfNode(propertyDecl), as that will get the // original symbol for the node. We actually want to get the symbol // created by checkObjectLiteral, since that will be appropriately // contextually typed and resolved. var type = getTypeOfSymbol(propertiesArray[i]); if (!ts.contains(propTypes, type)) { propTypes.push(type); } } } var result_1 = propTypes.length ? getUnionType(propTypes) : undefinedType; typeFlags |= result_1.flags; return result_1; } return undefined; }
Detect if the mapper implies an inference context. Specifically, there are 4 possible values for a mapper. Let's go through each one of them: 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, which could cause us to assign a parameter a type 2. identityMapper - means we want to avoid assigning a parameter a type, whether or not we are in inferential typing (context is undefined for the identityMapper) 3. a mapper created by createInferenceMapper - we are doing inferential typing, we want to assign types to parameters and fix type parameters (context is defined) 4. an instantiation mapper created by createTypeMapper or createTypeEraser - this should never be passed as the contextual mapper when checking an expression (context is undefined for these) isInferentialContext is detecting if we are in case 3
getIndexType
javascript
amol-/dukpy
dukpy/jsmodules/typescriptServices.js
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
MIT