MCPcopy Index your code
hub / github.com/nodejs/node / getConditionalFlowTypeOfType

Function getConditionalFlowTypeOfType

test/fixtures/snapshot/typescript.js:60477–60512  ·  view source on GitHub ↗
(type, node)

Source from the content-addressed store, hash-verified

60475 undefined;
60476 }
60477 function getConditionalFlowTypeOfType(type, node) {
60478 var constraints;
60479 var covariant = true;
60480 while (node && !ts.isStatement(node) && node.kind !== 320 /* SyntaxKind.JSDoc */) {
60481 var parent = node.parent;
60482 // only consider variance flipped by parameter locations - `keyof` types would usually be considered variance inverting, but
60483 // often get used in indexed accesses where they behave sortof invariantly, but our checking is lax
60484 if (parent.kind === 164 /* SyntaxKind.Parameter */) {
60485 covariant = !covariant;
60486 }
60487 // Always substitute on type parameters, regardless of variance, since even
60488 // in contravariant positions, they may rely on substituted constraints to be valid
60489 if ((covariant || type.flags & 8650752 /* TypeFlags.TypeVariable */) && parent.kind === 189 /* SyntaxKind.ConditionalType */ && node === parent.trueType) {
60490 var constraint = getImpliedConstraint(type, parent.checkType, parent.extendsType);
60491 if (constraint) {
60492 constraints = ts.append(constraints, constraint);
60493 }
60494 }
60495 // Given a homomorphic mapped type { [K in keyof T]: XXX }, where T is constrained to an array or tuple type, in the
60496 // template type XXX, K has an added constraint of number | `${number}`.
60497 else if (type.flags & 262144 /* TypeFlags.TypeParameter */ && parent.kind === 195 /* SyntaxKind.MappedType */ && node === parent.type) {
60498 var mappedType = getTypeFromTypeNode(parent);
60499 if (getTypeParameterFromMappedType(mappedType) === getActualTypeVariable(type)) {
60500 var typeParameter = getHomomorphicTypeVariable(mappedType);
60501 if (typeParameter) {
60502 var constraint = getConstraintOfTypeParameter(typeParameter);
60503 if (constraint && everyType(constraint, isArrayOrTupleType)) {
60504 constraints = ts.append(constraints, getUnionType([numberType, numericStringType]));
60505 }
60506 }
60507 }
60508 }
60509 node = parent;
60510 }
60511 return constraints ? getSubstitutionType(type, getIntersectionType(ts.append(constraints, type))) : type;
60512 }
60513 function isJSDocTypeReference(node) {
60514 return !!(node.flags & 8388608 /* NodeFlags.JSDoc */) && (node.kind === 178 /* SyntaxKind.TypeReference */ || node.kind === 200 /* SyntaxKind.ImportType */);
60515 }

Callers 2

getTypeFromTypeNodeFunction · 0.85

Calls 11

getImpliedConstraintFunction · 0.85
getTypeFromTypeNodeFunction · 0.85
getActualTypeVariableFunction · 0.85
everyTypeFunction · 0.85
getUnionTypeFunction · 0.85
getSubstitutionTypeFunction · 0.85
getIntersectionTypeFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…