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

Function getWidenedTypeWithContext

test/fixtures/snapshot/typescript.js:67839–67871  ·  view source on GitHub ↗
(type, context)

Source from the content-addressed store, hash-verified

67837 return getWidenedTypeWithContext(type, /*context*/ undefined);
67838 }
67839 function getWidenedTypeWithContext(type, context) {
67840 if (ts.getObjectFlags(type) & 196608 /* ObjectFlags.RequiresWidening */) {
67841 if (context === undefined && type.widened) {
67842 return type.widened;
67843 }
67844 var result = void 0;
67845 if (type.flags & (1 /* TypeFlags.Any */ | 98304 /* TypeFlags.Nullable */)) {
67846 result = anyType;
67847 }
67848 else if (isObjectLiteralType(type)) {
67849 result = getWidenedTypeOfObjectLiteral(type, context);
67850 }
67851 else if (type.flags & 1048576 /* TypeFlags.Union */) {
67852 var unionContext_1 = context || createWideningContext(/*parent*/ undefined, /*propertyName*/ undefined, type.types);
67853 var widenedTypes = ts.sameMap(type.types, function (t) { return t.flags & 98304 /* TypeFlags.Nullable */ ? t : getWidenedTypeWithContext(t, unionContext_1); });
67854 // Widening an empty object literal transitions from a highly restrictive type to
67855 // a highly inclusive one. For that reason we perform subtype reduction here if the
67856 // union includes empty object types (e.g. reducing {} | string to just {}).
67857 result = getUnionType(widenedTypes, ts.some(widenedTypes, isEmptyObjectType) ? 2 /* UnionReduction.Subtype */ : 1 /* UnionReduction.Literal */);
67858 }
67859 else if (type.flags & 2097152 /* TypeFlags.Intersection */) {
67860 result = getIntersectionType(ts.sameMap(type.types, getWidenedType));
67861 }
67862 else if (isArrayOrTupleType(type)) {
67863 result = createTypeReference(type.target, ts.sameMap(getTypeArguments(type), getWidenedType));
67864 }
67865 if (result && context === undefined) {
67866 type.widened = result;
67867 }
67868 return result || type;
67869 }
67870 return type;
67871 }
67872 /**
67873 * Reports implicit any errors that occur as a result of widening 'null' and 'undefined'
67874 * to 'any'. A call to reportWideningErrorsInType is normally accompanied by a call to

Callers 2

getWidenedPropertyFunction · 0.85
getWidenedTypeFunction · 0.85

Calls 9

isObjectLiteralTypeFunction · 0.85
createWideningContextFunction · 0.85
getUnionTypeFunction · 0.85
getIntersectionTypeFunction · 0.85
isArrayOrTupleTypeFunction · 0.85
createTypeReferenceFunction · 0.85
getTypeArgumentsFunction · 0.85
someMethod · 0.80

Tested by

no test coverage detected