@@ -10206,7 +10206,8 @@ namespace ts {
10206
10206
sig.resolvedMinArgumentCount = undefined;
10207
10207
sig.target = undefined;
10208
10208
sig.mapper = undefined;
10209
- sig.unionSignatures = undefined;
10209
+ sig.compositeSignatures = undefined;
10210
+ sig.compositeKind = undefined;
10210
10211
return sig;
10211
10212
}
10212
10213
@@ -10215,13 +10216,15 @@ namespace ts {
10215
10216
/*resolvedTypePredicate*/ undefined, sig.minArgumentCount, sig.flags & SignatureFlags.PropagatingFlags);
10216
10217
result.target = sig.target;
10217
10218
result.mapper = sig.mapper;
10218
- result.unionSignatures = sig.unionSignatures;
10219
+ result.compositeSignatures = sig.compositeSignatures;
10220
+ result.compositeKind = sig.compositeKind;
10219
10221
return result;
10220
10222
}
10221
10223
10222
10224
function createUnionSignature(signature: Signature, unionSignatures: Signature[]) {
10223
10225
const result = cloneSignature(signature);
10224
- result.unionSignatures = unionSignatures;
10226
+ result.compositeSignatures = unionSignatures;
10227
+ result.compositeKind = TypeFlags.Union;
10225
10228
result.target = undefined;
10226
10229
result.mapper = undefined;
10227
10230
return result;
@@ -10495,9 +10498,10 @@ namespace ts {
10495
10498
minArgCount,
10496
10499
(left.flags | right.flags) & SignatureFlags.PropagatingFlags
10497
10500
);
10498
- result.unionSignatures = concatenate(left.unionSignatures || [left], [right]);
10501
+ result.compositeKind = TypeFlags.Union;
10502
+ result.compositeSignatures = concatenate(left.compositeKind !== TypeFlags.Intersection && left.compositeSignatures || [left], [right]);
10499
10503
if (paramMapper) {
10500
- result.mapper = left.mapper && left.unionSignatures ? combineTypeMappers(left.mapper, paramMapper) : paramMapper;
10504
+ result.mapper = left.compositeKind !== TypeFlags.Intersection && left. mapper && left.compositeSignatures ? combineTypeMappers(left.mapper, paramMapper) : paramMapper;
10501
10505
}
10502
10506
return result;
10503
10507
}
@@ -12015,8 +12019,8 @@ namespace ts {
12015
12019
const targetTypePredicate = getTypePredicateOfSignature(signature.target);
12016
12020
signature.resolvedTypePredicate = targetTypePredicate ? instantiateTypePredicate(targetTypePredicate, signature.mapper!) : noTypePredicate;
12017
12021
}
12018
- else if (signature.unionSignatures ) {
12019
- signature.resolvedTypePredicate = getUnionTypePredicate (signature.unionSignatures ) || noTypePredicate;
12022
+ else if (signature.compositeSignatures ) {
12023
+ signature.resolvedTypePredicate = getUnionOrIntersectionTypePredicate (signature.compositeSignatures, signature.compositeKind ) || noTypePredicate;
12020
12024
}
12021
12025
else {
12022
12026
const type = signature.declaration && getEffectiveReturnTypeNode(signature.declaration);
@@ -12045,13 +12049,17 @@ namespace ts {
12045
12049
findIndex(signature.parameters, p => p.escapedName === parameterName.escapedText), type);
12046
12050
}
12047
12051
12052
+ function getUnionOrIntersectionType(types: Type[], kind: TypeFlags | undefined, unionReduction?: UnionReduction) {
12053
+ return kind !== TypeFlags.Intersection ? getUnionType(types, unionReduction) : getIntersectionType(types);
12054
+ }
12055
+
12048
12056
function getReturnTypeOfSignature(signature: Signature): Type {
12049
12057
if (!signature.resolvedReturnType) {
12050
12058
if (!pushTypeResolution(signature, TypeSystemPropertyName.ResolvedReturnType)) {
12051
12059
return errorType;
12052
12060
}
12053
12061
let type = signature.target ? instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper) :
12054
- signature.unionSignatures ? instantiateType(getUnionType (map(signature.unionSignatures , getReturnTypeOfSignature), UnionReduction.Subtype), signature.mapper) :
12062
+ signature.compositeSignatures ? instantiateType(getUnionOrIntersectionType (map(signature.compositeSignatures , getReturnTypeOfSignature), signature.compositeKind , UnionReduction.Subtype), signature.mapper) :
12055
12063
getReturnTypeFromAnnotation(signature.declaration!) ||
12056
12064
(nodeIsMissing((<FunctionLikeDeclaration>signature.declaration).body) ? anyType : getReturnTypeFromBody(<FunctionLikeDeclaration>signature.declaration));
12057
12065
if (signature.flags & SignatureFlags.IsInnerCallChain) {
@@ -13481,13 +13489,18 @@ namespace ts {
13481
13489
return getUnionTypeFromSortedList(typeSet, objectFlags, aliasSymbol, aliasTypeArguments, origin);
13482
13490
}
13483
13491
13484
- function getUnionTypePredicate (signatures: readonly Signature[]): TypePredicate | undefined {
13492
+ function getUnionOrIntersectionTypePredicate (signatures: readonly Signature[], kind: TypeFlags | undefined ): TypePredicate | undefined {
13485
13493
let first: TypePredicate | undefined;
13486
13494
const types: Type[] = [];
13487
13495
for (const sig of signatures) {
13488
13496
const pred = getTypePredicateOfSignature(sig);
13489
13497
if (!pred || pred.kind === TypePredicateKind.AssertsThis || pred.kind === TypePredicateKind.AssertsIdentifier) {
13490
- continue;
13498
+ if (kind !== TypeFlags.Intersection) {
13499
+ continue;
13500
+ }
13501
+ else {
13502
+ return; // intersections demand all members be type predicates for the result to have a predicate
13503
+ }
13491
13504
}
13492
13505
13493
13506
if (first) {
@@ -13502,11 +13515,11 @@ namespace ts {
13502
13515
types.push(pred.type);
13503
13516
}
13504
13517
if (!first) {
13505
- // No union signatures had a type predicate.
13518
+ // No signatures had a type predicate.
13506
13519
return undefined;
13507
13520
}
13508
- const unionType = getUnionType(types);
13509
- return createTypePredicate(first.kind, first.parameterName, first.parameterIndex, unionType );
13521
+ const compositeType = kind !== TypeFlags.Intersection ? getUnionType(types) : getIntersectionType (types);
13522
+ return createTypePredicate(first.kind, first.parameterName, first.parameterIndex, compositeType );
13510
13523
}
13511
13524
13512
13525
function typePredicateKindsMatch(a: TypePredicate, b: TypePredicate): boolean {
@@ -24812,14 +24825,14 @@ namespace ts {
24812
24825
}
24813
24826
24814
24827
function getJsxPropsTypeForSignatureFromMember(sig: Signature, forcedLookupLocation: __String) {
24815
- if (sig.unionSignatures ) {
24828
+ if (sig.compositeSignatures ) {
24816
24829
// JSX Elements using the legacy `props`-field based lookup (eg, react class components) need to treat the `props` member as an input
24817
24830
// instead of an output position when resolving the signature. We need to go back to the input signatures of the composite signature,
24818
24831
// get the type of `props` on each return type individually, and then _intersect them_, rather than union them (as would normally occur
24819
24832
// for a union signature). It's an unfortunate quirk of looking in the output of the signature for the type we want to use for the input.
24820
24833
// The default behavior of `getTypeOfFirstParameterOfSignatureWithFallback` when no `props` member name is defined is much more sane.
24821
24834
const results: Type[] = [];
24822
- for (const signature of sig.unionSignatures ) {
24835
+ for (const signature of sig.compositeSignatures ) {
24823
24836
const instance = getReturnTypeOfSignature(signature);
24824
24837
if (isTypeAny(instance)) {
24825
24838
return instance;
@@ -24830,7 +24843,7 @@ namespace ts {
24830
24843
}
24831
24844
results.push(propType);
24832
24845
}
24833
- return getIntersectionType(results);
24846
+ return getIntersectionType(results); // Same result for both union and intersection signatures
24834
24847
}
24835
24848
const instanceType = getReturnTypeOfSignature(sig);
24836
24849
return isTypeAny(instanceType) ? instanceType : getTypeOfPropertyOfType(instanceType, forcedLookupLocation);
@@ -25006,9 +25019,10 @@ namespace ts {
25006
25019
minArgCount,
25007
25020
(left.flags | right.flags) & SignatureFlags.PropagatingFlags
25008
25021
);
25009
- result.unionSignatures = concatenate(left.unionSignatures || [left], [right]);
25022
+ result.compositeKind = TypeFlags.Intersection;
25023
+ result.compositeSignatures = concatenate(left.compositeKind === TypeFlags.Intersection && left.compositeSignatures || [left], [right]);
25010
25024
if (paramMapper) {
25011
- result.mapper = left.mapper && left.unionSignatures ? combineTypeMappers(left.mapper, paramMapper) : paramMapper;
25025
+ result.mapper = left.compositeKind === TypeFlags.Intersection && left. mapper && left.compositeSignatures ? combineTypeMappers(left.mapper, paramMapper) : paramMapper;
25012
25026
}
25013
25027
return result;
25014
25028
}
0 commit comments