Skip to content

Conditional types #21316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Feb 3, 2018
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
57ca768
Initial implementation of conditional type operator
ahejlsberg Dec 5, 2017
063eed1
Add type relationships and distribute over union types
ahejlsberg Dec 8, 2017
ec2bdfd
Add 'T extends U' type operator
ahejlsberg Dec 12, 2017
43e195d
Clean up isGenericXXXType functions
ahejlsberg Dec 12, 2017
61225cc
Introduce TypeFlags.Instatiable
ahejlsberg Dec 13, 2017
9f74a7a
Rename TypeVariable to InstantiableType
ahejlsberg Dec 13, 2017
20434fa
Inference for conditional and extends type operators
ahejlsberg Dec 13, 2017
ddc631c
Fix typo
ahejlsberg Dec 13, 2017
000f121
Improve conditional type constraint checking
ahejlsberg Dec 13, 2017
27b945b
Handle constraints for distributive conditional types
ahejlsberg Dec 16, 2017
f59e2e6
Accept new baselines
ahejlsberg Dec 17, 2017
14590f1
Move JsxAttributes and MarkerType from TypeFlags to ObjectFlags
ahejlsberg Dec 18, 2017
100e4f6
Accept new baselines
ahejlsberg Dec 18, 2017
c5fd2f1
Parse xxx? as JSDoc type when not followed by token that starts type
ahejlsberg Dec 19, 2017
341c397
Accept new baselines
ahejlsberg Dec 19, 2017
3f4911f
Fix linting error
ahejlsberg Dec 20, 2017
abc8110
Merge branch 'master' into conditionalTypes
ahejlsberg Jan 3, 2018
bb23bb2
Propagate both TypeFlags and ObjectFlags in getSpreadType
ahejlsberg Jan 3, 2018
c10a552
Eagerly evaluate S extends T when S is definitely or definitely not a…
ahejlsberg Jan 14, 2018
53b1572
Revert to extends check being part of conditional type
ahejlsberg Jan 15, 2018
5094f76
Remove 'T extends U' type constructor
ahejlsberg Jan 15, 2018
925da86
Accept new baselines
ahejlsberg Jan 15, 2018
e8d1740
Introduce substitution types to use for constrained type parameters
ahejlsberg Jan 15, 2018
15baf0e
Accept new baselines
ahejlsberg Jan 15, 2018
9598acd
Properly handle 'any' and 'never' as conditional check type
ahejlsberg Jan 15, 2018
e96ec8c
Erase substitution types in type references and type alias instantiat…
ahejlsberg Jan 16, 2018
d52fa71
Optimize the sameMap function
ahejlsberg Jan 16, 2018
4ec6fdd
Merge branch 'master' into conditionalTypes
ahejlsberg Jan 17, 2018
fd0dd6e
Separate code path for conditional type instantiation
ahejlsberg Jan 18, 2018
c360c24
Fix parsing
ahejlsberg Jan 19, 2018
0e73240
Disallow conditional type following 'extends'
ahejlsberg Jan 19, 2018
5204fd5
Add T is related to { [P in xxx]: T[P] } type relationship
ahejlsberg Jan 20, 2018
eb314d0
Add tests
ahejlsberg Jan 20, 2018
cdd50d4
Accept new baselines
ahejlsberg Jan 20, 2018
fc7d1c3
Revise comments
ahejlsberg Jan 20, 2018
f19959a
Cache substitution types and remove erasure that was too eager
ahejlsberg Jan 20, 2018
b869290
Remove unnecessary caching of substitution types
ahejlsberg Jan 21, 2018
4c7ec3c
Shared code path for getConditionalType and instantiateConditionalType
ahejlsberg Jan 21, 2018
b42c6b1
Only conditional types that check naked type parameter distribute ove…
ahejlsberg Jan 24, 2018
8e337b5
Fix bug in resolveMappedTypeMembers
ahejlsberg Jan 24, 2018
4f2b5f3
Merge branch 'master' into conditionalTypes
ahejlsberg Jan 30, 2018
f990e4e
Merge branch 'master' into conditionalTypes
ahejlsberg Jan 30, 2018
01516c8
Update to use TypeFlags.Instantiable in instantiateSymbol
ahejlsberg Jan 30, 2018
d4dc67a
Merge branch 'master' into conditionalTypes
ahejlsberg Feb 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Propagate both TypeFlags and ObjectFlags in getSpreadType
  • Loading branch information
ahejlsberg committed Jan 3, 2018
commit bb23bb2a9248afb8eb357fffe312e8f9313f6649
29 changes: 15 additions & 14 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8442,7 +8442,7 @@ namespace ts {
function getExtendsType(checkType: Type, extendsType: Type): Type {
// sys.write(`getExtendsType(${typeToString(checkType)}, ${typeToString(extendsType)})\n`);
if (checkType.flags & TypeFlags.Union) {
return getUnionType(map((<UnionType>checkType).types, t => getExtendsType(t, extendsType)), /*subtypeReduction*/ false);
return getUnionType(map((<UnionType>checkType).types, t => getExtendsType(t, extendsType)));
}
if (checkType.flags & TypeFlags.Any) {
return booleanType;
Expand Down Expand Up @@ -8501,7 +8501,7 @@ namespace ts {
* this function should be called in a left folding style, with left = previous result of getSpreadType
* and right = the new element to be spread.
*/
function getSpreadType(left: Type, right: Type, symbol: Symbol, propagatedFlags: TypeFlags): Type {
function getSpreadType(left: Type, right: Type, symbol: Symbol, typeFlags: TypeFlags, objectFlags: ObjectFlags): Type {
if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) {
return anyType;
}
Expand All @@ -8512,10 +8512,10 @@ namespace ts {
return left;
}
if (left.flags & TypeFlags.Union) {
return mapType(left, t => getSpreadType(t, right, symbol, propagatedFlags));
return mapType(left, t => getSpreadType(t, right, symbol, typeFlags, objectFlags));
}
if (right.flags & TypeFlags.Union) {
return mapType(right, t => getSpreadType(left, t, symbol, propagatedFlags));
return mapType(right, t => getSpreadType(left, t, symbol, typeFlags, objectFlags));
}
if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive)) {
return left;
Expand Down Expand Up @@ -8578,8 +8578,8 @@ namespace ts {
emptyArray,
getNonReadonlyIndexSignature(stringIndexInfo),
getNonReadonlyIndexSignature(numberIndexInfo));
spread.flags |= propagatedFlags | TypeFlags.ContainsObjectLiteral;
(spread as ObjectType).objectFlags |= (ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread);
spread.flags |= typeFlags | TypeFlags.ContainsObjectLiteral;
(spread as ObjectType).objectFlags |= objectFlags | (ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread);
return spread;
}

Expand Down Expand Up @@ -9552,7 +9552,7 @@ namespace ts {
}

function isIgnoredJsxProperty(source: Type, sourceProp: Symbol, targetMemberType: Type | undefined) {
return source.flags & TypeFlags.JsxAttributes && !(isUnhyphenatedJsxName(sourceProp.escapedName) || targetMemberType);
return getObjectFlags(source) & ObjectFlags.JsxAttributes && !(isUnhyphenatedJsxName(sourceProp.escapedName) || targetMemberType);
}

/**
Expand Down Expand Up @@ -14905,7 +14905,7 @@ namespace ts {
checkExternalEmitHelpers(memberDecl, ExternalEmitHelpers.Assign);
}
if (propertiesArray.length > 0) {
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags);
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, 0);
propertiesArray = [];
propertiesTable = createSymbolTable();
hasComputedStringProperty = false;
Expand All @@ -14917,7 +14917,7 @@ namespace ts {
error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
return unknownType;
}
spread = getSpreadType(spread, type, node.symbol, propagatedFlags);
spread = getSpreadType(spread, type, node.symbol, propagatedFlags, 0);
offset = i + 1;
continue;
}
Expand Down Expand Up @@ -14962,7 +14962,7 @@ namespace ts {

if (spread !== emptyObjectType) {
if (propertiesArray.length > 0) {
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags);
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, 0);
}
return spread;
}
Expand Down Expand Up @@ -15095,15 +15095,15 @@ namespace ts {
else {
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);
if (attributesTable.size > 0) {
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, TypeFlags.JsxAttributes);
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, 0, ObjectFlags.JsxAttributes);
attributesTable = createSymbolTable();
}
const exprType = checkExpressionCached(attributeDecl.expression, checkMode);
if (isTypeAny(exprType)) {
hasSpreadAnyType = true;
}
if (isValidSpreadType(exprType)) {
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, TypeFlags.JsxAttributes);
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, 0, ObjectFlags.JsxAttributes);
}
else {
typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
Expand All @@ -15113,7 +15113,7 @@ namespace ts {

if (!hasSpreadAnyType) {
if (attributesTable.size > 0) {
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, TypeFlags.JsxAttributes);
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, 0, ObjectFlags.JsxAttributes);
}
}

Expand All @@ -15138,7 +15138,8 @@ namespace ts {
createArrayType(getUnionType(childrenTypes));
const childPropMap = createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, TypeFlags.JsxAttributes);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined),
attributes.symbol, 0, ObjectFlags.JsxAttributes);

}
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy