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

Function combineAnonymousTypes

test/fixtures/snapshot/typescript.js:157296–157338  ·  view source on GitHub ↗
(anons)

Source from the content-addressed store, hash-verified

157294 return checker.getWidenedType(checker.getUnionType(good.map(checker.getBaseTypeOfLiteralType), 2 /* UnionReduction.Subtype */));
157295 }
157296 function combineAnonymousTypes(anons) {
157297 if (anons.length === 1) {
157298 return anons[0];
157299 }
157300 var calls = [];
157301 var constructs = [];
157302 var stringIndices = [];
157303 var numberIndices = [];
157304 var stringIndexReadonly = false;
157305 var numberIndexReadonly = false;
157306 var props = ts.createMultiMap();
157307 for (var _i = 0, anons_1 = anons; _i < anons_1.length; _i++) {
157308 var anon = anons_1[_i];
157309 for (var _a = 0, _b = checker.getPropertiesOfType(anon); _a < _b.length; _a++) {
157310 var p = _b[_a];
157311 props.add(p.name, p.valueDeclaration ? checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration) : checker.getAnyType());
157312 }
157313 calls.push.apply(calls, checker.getSignaturesOfType(anon, 0 /* SignatureKind.Call */));
157314 constructs.push.apply(constructs, checker.getSignaturesOfType(anon, 1 /* SignatureKind.Construct */));
157315 var stringIndexInfo = checker.getIndexInfoOfType(anon, 0 /* IndexKind.String */);
157316 if (stringIndexInfo) {
157317 stringIndices.push(stringIndexInfo.type);
157318 stringIndexReadonly = stringIndexReadonly || stringIndexInfo.isReadonly;
157319 }
157320 var numberIndexInfo = checker.getIndexInfoOfType(anon, 1 /* IndexKind.Number */);
157321 if (numberIndexInfo) {
157322 numberIndices.push(numberIndexInfo.type);
157323 numberIndexReadonly = numberIndexReadonly || numberIndexInfo.isReadonly;
157324 }
157325 }
157326 var members = ts.mapEntries(props, function (name, types) {
157327 var isOptional = types.length < anons.length ? 16777216 /* SymbolFlags.Optional */ : 0;
157328 var s = checker.createSymbol(4 /* SymbolFlags.Property */ | isOptional, name);
157329 s.type = checker.getUnionType(types);
157330 return [name, s];
157331 });
157332 var indexInfos = [];
157333 if (stringIndices.length)
157334 indexInfos.push(checker.createIndexInfo(checker.getStringType(), checker.getUnionType(stringIndices), stringIndexReadonly));
157335 if (numberIndices.length)
157336 indexInfos.push(checker.createIndexInfo(checker.getNumberType(), checker.getUnionType(numberIndices), numberIndexReadonly));
157337 return checker.createAnonymousType(anons[0].symbol, members, calls, constructs, indexInfos);
157338 }
157339 function inferTypes(usage) {
157340 var _a, _b, _c;
157341 var types = [];

Callers 1

combineTypesFunction · 0.85

Calls 3

addMethod · 0.65
applyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected