mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #21316 from Microsoft/conditionalTypes
Conditional types
This commit is contained in:
@@ -3440,6 +3440,7 @@ namespace ts {
|
||||
case SyntaxKind.TupleType:
|
||||
case SyntaxKind.UnionType:
|
||||
case SyntaxKind.IntersectionType:
|
||||
case SyntaxKind.ConditionalType:
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
|
||||
+257
-62
@@ -306,6 +306,7 @@ namespace ts {
|
||||
const intersectionTypes = createMap<IntersectionType>();
|
||||
const literalTypes = createMap<LiteralType>();
|
||||
const indexedAccessTypes = createMap<IndexedAccessType>();
|
||||
const conditionalTypes = createMap<ConditionalType>();
|
||||
const evolvingArrayTypes: EvolvingArrayType[] = [];
|
||||
const undefinedProperties = createMap<Symbol>() as UnderscoreEscapedMap<Symbol>;
|
||||
|
||||
@@ -2955,6 +2956,16 @@ namespace ts {
|
||||
const indexTypeNode = typeToTypeNodeHelper((<IndexedAccessType>type).indexType, context);
|
||||
return createIndexedAccessTypeNode(objectTypeNode, indexTypeNode);
|
||||
}
|
||||
if (type.flags & TypeFlags.Conditional) {
|
||||
const checkTypeNode = typeToTypeNodeHelper((<ConditionalType>type).checkType, context);
|
||||
const extendsTypeNode = typeToTypeNodeHelper((<ConditionalType>type).extendsType, context);
|
||||
const trueTypeNode = typeToTypeNodeHelper((<ConditionalType>type).trueType, context);
|
||||
const falseTypeNode = typeToTypeNodeHelper((<ConditionalType>type).falseType, context);
|
||||
return createConditionalTypeNode(checkTypeNode, extendsTypeNode, trueTypeNode, falseTypeNode);
|
||||
}
|
||||
if (type.flags & TypeFlags.Substitution) {
|
||||
return typeToTypeNodeHelper((<SubstitutionType>type).typeParameter, context);
|
||||
}
|
||||
|
||||
Debug.fail("Should be unreachable.");
|
||||
|
||||
@@ -5829,7 +5840,7 @@ namespace ts {
|
||||
// and T as the template type.
|
||||
const typeParameter = getTypeParameterFromMappedType(type);
|
||||
const constraintType = getConstraintTypeFromMappedType(type);
|
||||
const templateType = getTemplateTypeFromMappedType(type);
|
||||
const templateType = getTemplateTypeFromMappedType(<MappedType>type.target || type);
|
||||
const modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
|
||||
const templateReadonly = !!type.declaration.readonlyToken;
|
||||
const templateOptional = !!type.declaration.questionToken;
|
||||
@@ -5848,7 +5859,7 @@ namespace ts {
|
||||
// First, if the constraint type is a type parameter, obtain the base constraint. Then,
|
||||
// if the key type is a 'keyof X', obtain 'keyof C' where C is the base constraint of X.
|
||||
// Finally, iterate over the constituents of the resulting iteration type.
|
||||
const keyType = constraintType.flags & TypeFlags.TypeVariable ? getApparentType(constraintType) : constraintType;
|
||||
const keyType = constraintType.flags & TypeFlags.InstantiableNonPrimitive ? getApparentType(constraintType) : constraintType;
|
||||
const iterationType = keyType.flags & TypeFlags.Index ? getIndexType(getApparentType((<IndexType>keyType).type)) : keyType;
|
||||
forEachType(iterationType, addMemberForKeyType);
|
||||
}
|
||||
@@ -6048,10 +6059,11 @@ namespace ts {
|
||||
return arrayFrom(props.values());
|
||||
}
|
||||
|
||||
function getConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type {
|
||||
function getConstraintOfType(type: InstantiableType | UnionOrIntersectionType): Type {
|
||||
return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) :
|
||||
type.flags & TypeFlags.IndexedAccess ? getConstraintOfIndexedAccess(<IndexedAccessType>type) :
|
||||
getBaseConstraintOfType(type);
|
||||
type.flags & TypeFlags.Conditional ? getConstraintOfConditionalType(<ConditionalType>type) :
|
||||
getBaseConstraintOfType(type);
|
||||
}
|
||||
|
||||
function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type {
|
||||
@@ -6073,9 +6085,33 @@ namespace ts {
|
||||
return baseObjectType || baseIndexType ? getIndexedAccessType(baseObjectType || type.objectType, baseIndexType || type.indexType) : undefined;
|
||||
}
|
||||
|
||||
function getDefaultConstraintOfConditionalType(type: ConditionalType) {
|
||||
return getUnionType([type.trueType, type.falseType]);
|
||||
}
|
||||
|
||||
function getConstraintOfDistributiveConditionalType(type: ConditionalType) {
|
||||
// Check if we have a conditional type of the form 'T extends U ? X : Y', where T is a constrained
|
||||
// type parameter. If so, create an instantiation of the conditional type where T is replaced
|
||||
// with its constraint. We do this because if the constraint is a union type it will be distributed
|
||||
// over the conditional type and possibly reduced. For example, 'T extends undefined ? never : T'
|
||||
// removes 'undefined' from T.
|
||||
const checkType = type.checkType;
|
||||
if (checkType.flags & TypeFlags.TypeParameter) {
|
||||
const constraint = getConstraintOfTypeParameter(<TypeParameter>checkType);
|
||||
if (constraint) {
|
||||
return instantiateType(type, createTypeMapper([<TypeParameter>checkType], [constraint]));
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getConstraintOfConditionalType(type: ConditionalType) {
|
||||
return getConstraintOfDistributiveConditionalType(type) || getDefaultConstraintOfConditionalType(type);
|
||||
}
|
||||
|
||||
function getBaseConstraintOfType(type: Type): Type {
|
||||
if (type.flags & (TypeFlags.TypeVariable | TypeFlags.UnionOrIntersection)) {
|
||||
const constraint = getResolvedBaseConstraint(<TypeVariable | UnionOrIntersectionType>type);
|
||||
if (type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.UnionOrIntersection)) {
|
||||
const constraint = getResolvedBaseConstraint(<InstantiableType | UnionOrIntersectionType>type);
|
||||
if (constraint !== noConstraintType && constraint !== circularConstraintType) {
|
||||
return constraint;
|
||||
}
|
||||
@@ -6086,7 +6122,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function hasNonCircularBaseConstraint(type: TypeVariable): boolean {
|
||||
function hasNonCircularBaseConstraint(type: InstantiableType): boolean {
|
||||
return getResolvedBaseConstraint(type) !== circularConstraintType;
|
||||
}
|
||||
|
||||
@@ -6095,7 +6131,7 @@ namespace ts {
|
||||
* type variable has no constraint, and the circularConstraintType singleton is returned if the constraint
|
||||
* circularly references the type variable.
|
||||
*/
|
||||
function getResolvedBaseConstraint(type: TypeVariable | UnionOrIntersectionType): Type {
|
||||
function getResolvedBaseConstraint(type: InstantiableType | UnionOrIntersectionType): Type {
|
||||
let circular: boolean;
|
||||
if (!type.resolvedBaseConstraint) {
|
||||
const constraint = getBaseConstraint(type);
|
||||
@@ -6149,6 +6185,12 @@ namespace ts {
|
||||
const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType) : undefined;
|
||||
return baseIndexedAccess && baseIndexedAccess !== unknownType ? getBaseConstraint(baseIndexedAccess) : undefined;
|
||||
}
|
||||
if (t.flags & TypeFlags.Conditional) {
|
||||
return getBaseConstraint(getConstraintOfConditionalType(<ConditionalType>t));
|
||||
}
|
||||
if (t.flags & TypeFlags.Substitution) {
|
||||
return getBaseConstraint((<SubstitutionType>t).substitute);
|
||||
}
|
||||
if (isGenericMappedType(t)) {
|
||||
return emptyObjectType;
|
||||
}
|
||||
@@ -6213,7 +6255,7 @@ namespace ts {
|
||||
* type itself. Note that the apparent type of a union type is the union type itself.
|
||||
*/
|
||||
function getApparentType(type: Type): Type {
|
||||
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(type) || emptyObjectType : type;
|
||||
const t = type.flags & TypeFlags.Instantiable ? getBaseConstraintOfType(type) || emptyObjectType : type;
|
||||
return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>t) :
|
||||
t.flags & TypeFlags.StringLike ? globalStringType :
|
||||
t.flags & TypeFlags.NumberLike ? globalNumberType :
|
||||
@@ -7127,7 +7169,7 @@ namespace ts {
|
||||
error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol));
|
||||
return unknownType;
|
||||
}
|
||||
return res;
|
||||
return res.flags & TypeFlags.TypeParameter ? getConstrainedTypeParameter(<TypeParameter>res, node) : res;
|
||||
}
|
||||
|
||||
if (!(symbol.flags & SymbolFlags.Value && isJSDocTypeReference(node))) {
|
||||
@@ -7166,6 +7208,27 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getSubstitutionType(typeParameter: TypeParameter, substitute: Type) {
|
||||
const result = <SubstitutionType>createType(TypeFlags.Substitution);
|
||||
result.typeParameter = typeParameter;
|
||||
result.substitute = substitute;
|
||||
return result;
|
||||
}
|
||||
|
||||
function getConstrainedTypeParameter(typeParameter: TypeParameter, node: Node) {
|
||||
let constraints: Type[];
|
||||
while (isTypeNode(node)) {
|
||||
const parent = node.parent;
|
||||
if (parent.kind === SyntaxKind.ConditionalType && node === (<ConditionalTypeNode>parent).trueType) {
|
||||
if (getTypeFromTypeNode((<ConditionalTypeNode>parent).checkType) === typeParameter) {
|
||||
constraints = append(constraints, getTypeFromTypeNode((<ConditionalTypeNode>parent).extendsType));
|
||||
}
|
||||
}
|
||||
node = parent;
|
||||
}
|
||||
return constraints ? getSubstitutionType(typeParameter, getIntersectionType(append(constraints, typeParameter))) : typeParameter;
|
||||
}
|
||||
|
||||
function isJSDocTypeReference(node: TypeReferenceType): node is TypeReferenceNode {
|
||||
return node.flags & NodeFlags.JSDoc && node.kind === SyntaxKind.TypeReference;
|
||||
}
|
||||
@@ -7798,7 +7861,7 @@ namespace ts {
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function getIndexTypeForGenericType(type: TypeVariable | UnionOrIntersectionType) {
|
||||
function getIndexTypeForGenericType(type: InstantiableType | UnionOrIntersectionType) {
|
||||
if (!type.resolvedIndexType) {
|
||||
type.resolvedIndexType = <IndexType>createType(TypeFlags.Index);
|
||||
type.resolvedIndexType.type = type;
|
||||
@@ -7817,10 +7880,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getIndexType(type: Type): Type {
|
||||
return maybeTypeOfKind(type, TypeFlags.TypeVariable) ? getIndexTypeForGenericType(<TypeVariable | UnionOrIntersectionType>type) :
|
||||
return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive) ? getIndexTypeForGenericType(<InstantiableType | UnionOrIntersectionType>type) :
|
||||
getObjectFlags(type) & ObjectFlags.Mapped ? getConstraintTypeFromMappedType(<MappedType>type) :
|
||||
type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringType :
|
||||
getLiteralTypeFromPropertyNames(type);
|
||||
type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringType :
|
||||
getLiteralTypeFromPropertyNames(type);
|
||||
}
|
||||
|
||||
function getIndexTypeOrString(type: Type): Type {
|
||||
@@ -7916,16 +7979,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isGenericObjectType(type: Type): boolean {
|
||||
return type.flags & TypeFlags.TypeVariable ? true :
|
||||
getObjectFlags(type) & ObjectFlags.Mapped ? isGenericIndexType(getConstraintTypeFromMappedType(<MappedType>type)) :
|
||||
type.flags & TypeFlags.UnionOrIntersection ? forEach((<UnionOrIntersectionType>type).types, isGenericObjectType) :
|
||||
false;
|
||||
return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.GenericMappedType);
|
||||
}
|
||||
|
||||
function isGenericIndexType(type: Type): boolean {
|
||||
return type.flags & (TypeFlags.TypeVariable | TypeFlags.Index) ? true :
|
||||
type.flags & TypeFlags.UnionOrIntersection ? forEach((<UnionOrIntersectionType>type).types, isGenericIndexType) :
|
||||
false;
|
||||
return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index);
|
||||
}
|
||||
|
||||
// Return true if the given type is a non-generic object type with a string index signature and no
|
||||
@@ -8060,6 +8118,65 @@ namespace ts {
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function getActualTypeParameter(type: Type) {
|
||||
return type.flags & TypeFlags.Substitution ? (<SubstitutionType>type).typeParameter : type;
|
||||
}
|
||||
|
||||
function createConditionalType(checkType: Type, extendsType: Type, trueType: Type, falseType: Type, target: ConditionalType, mapper: TypeMapper, aliasSymbol: Symbol, aliasTypeArguments: Type[]) {
|
||||
const type = <ConditionalType>createType(TypeFlags.Conditional);
|
||||
type.checkType = checkType;
|
||||
type.extendsType = extendsType;
|
||||
type.trueType = trueType;
|
||||
type.falseType = falseType;
|
||||
type.target = target;
|
||||
type.mapper = mapper;
|
||||
type.aliasSymbol = aliasSymbol;
|
||||
type.aliasTypeArguments = aliasTypeArguments;
|
||||
return type;
|
||||
}
|
||||
|
||||
function getConditionalType(checkType: Type, extendsType: Type, baseTrueType: Type, baseFalseType: Type, target: ConditionalType, mapper: TypeMapper, aliasSymbol?: Symbol, baseAliasTypeArguments?: Type[]): Type {
|
||||
// Return union of trueType and falseType for any and never since they match anything
|
||||
if (checkType.flags & (TypeFlags.Any | TypeFlags.Never)) {
|
||||
return getUnionType([instantiateType(baseTrueType, mapper), instantiateType(baseFalseType, mapper)]);
|
||||
}
|
||||
// Return trueType for a definitely true extends check
|
||||
if (isTypeAssignableTo(checkType, extendsType)) {
|
||||
return instantiateType(baseTrueType, mapper);
|
||||
}
|
||||
// Return falseType for a definitely false extends check
|
||||
if (!isTypeAssignableTo(instantiateType(checkType, anyMapper), instantiateType(extendsType, constraintMapper))) {
|
||||
return instantiateType(baseFalseType, mapper);
|
||||
}
|
||||
// Return a deferred type for a check that is neither definitely true nor definitely false
|
||||
const erasedCheckType = getActualTypeParameter(checkType);
|
||||
const trueType = instantiateType(baseTrueType, mapper);
|
||||
const falseType = instantiateType(baseFalseType, mapper);
|
||||
const id = target && (target.id + "," + erasedCheckType.id + "," + extendsType.id + "," + trueType.id + "," + falseType.id);
|
||||
const cached = id && conditionalTypes.get(id);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const result = createConditionalType(erasedCheckType, extendsType, trueType, falseType,
|
||||
target, mapper, aliasSymbol, instantiateTypes(baseAliasTypeArguments, mapper));
|
||||
if (id) {
|
||||
conditionalTypes.set(id, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getTypeFromConditionalTypeNode(node: ConditionalTypeNode): Type {
|
||||
const links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
links.resolvedType = getConditionalType(
|
||||
getTypeFromTypeNode(node.checkType), getTypeFromTypeNode(node.extendsType),
|
||||
getTypeFromTypeNode(node.trueType), getTypeFromTypeNode(node.falseType),
|
||||
/*target*/ undefined, /*mapper*/ undefined,
|
||||
getAliasSymbolForTypeNode(node), getAliasTypeArgumentsForTypeNode(node));
|
||||
}
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node: TypeNode): Type {
|
||||
const links = getNodeLinks(node);
|
||||
if (!links.resolvedType) {
|
||||
@@ -8095,7 +8212,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;
|
||||
}
|
||||
@@ -8106,10 +8223,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;
|
||||
@@ -8172,8 +8289,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;
|
||||
}
|
||||
|
||||
@@ -8348,6 +8465,8 @@ namespace ts {
|
||||
return getTypeFromIndexedAccessTypeNode(<IndexedAccessTypeNode>node);
|
||||
case SyntaxKind.MappedType:
|
||||
return getTypeFromMappedTypeNode(<MappedTypeNode>node);
|
||||
case SyntaxKind.ConditionalType:
|
||||
return getTypeFromConditionalTypeNode(<ConditionalTypeNode>node);
|
||||
// This function assumes that an identifier or qualified name is a type expression
|
||||
// Callers should first ensure this by calling isTypeNode
|
||||
case SyntaxKind.Identifier:
|
||||
@@ -8441,6 +8560,14 @@ namespace ts {
|
||||
return t => t === source ? target : baseMapper(t);
|
||||
}
|
||||
|
||||
function anyMapper(type: Type) {
|
||||
return type.flags & TypeFlags.TypeParameter ? anyType : type;
|
||||
}
|
||||
|
||||
function constraintMapper(type: Type) {
|
||||
return type.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>type) || anyType : type;
|
||||
}
|
||||
|
||||
function cloneTypeParameter(typeParameter: TypeParameter): TypeParameter {
|
||||
const result = <TypeParameter>createType(TypeFlags.TypeParameter);
|
||||
result.symbol = typeParameter.symbol;
|
||||
@@ -8495,7 +8622,7 @@ namespace ts {
|
||||
|
||||
function instantiateSymbol(symbol: Symbol, mapper: TypeMapper): Symbol {
|
||||
const links = getSymbolLinks(symbol);
|
||||
if (links.type && !maybeTypeOfKind(links.type, TypeFlags.Object | TypeFlags.TypeVariable | TypeFlags.Index)) {
|
||||
if (links.type && !maybeTypeOfKind(links.type, TypeFlags.Object | TypeFlags.Instantiable)) {
|
||||
// If the type of the symbol is already resolved, and if that type could not possibly
|
||||
// be affected by instantiation, simply return the symbol itself.
|
||||
return symbol;
|
||||
@@ -8626,8 +8753,29 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function getConditionalTypeInstantiation(type: ConditionalType, mapper: TypeMapper): Type {
|
||||
const target = type.target || type;
|
||||
const combinedMapper = type.mapper ? combineTypeMappers(type.mapper, mapper) : mapper;
|
||||
// Check if we have a conditional type where the check type is a naked type parameter. If so,
|
||||
// the conditional type is distributive over union types and when T is instantiated to a union
|
||||
// type A | B, we produce (A extends U ? X : Y) | (B extends U ? X : Y).
|
||||
const checkType = target.checkType;
|
||||
if (checkType.flags & TypeFlags.TypeParameter) {
|
||||
const instantiatedType = combinedMapper(<TypeParameter>checkType);
|
||||
if (checkType !== instantiatedType && instantiatedType.flags & TypeFlags.Union) {
|
||||
return mapType(instantiatedType, t => instantiateConditionalType(target, createReplacementMapper(checkType, t, combinedMapper)));
|
||||
}
|
||||
}
|
||||
return instantiateConditionalType(target, combinedMapper);
|
||||
}
|
||||
|
||||
function instantiateConditionalType(type: ConditionalType, mapper: TypeMapper): Type {
|
||||
return getConditionalType(instantiateType(type.checkType, mapper), instantiateType(type.extendsType, mapper),
|
||||
type.trueType, type.falseType, type, mapper, type.aliasSymbol, type.aliasTypeArguments);
|
||||
}
|
||||
|
||||
function instantiateType(type: Type, mapper: TypeMapper): Type {
|
||||
if (type && mapper !== identityMapper) {
|
||||
if (type && mapper && mapper !== identityMapper) {
|
||||
if (type.flags & TypeFlags.TypeParameter) {
|
||||
return mapper(<TypeParameter>type);
|
||||
}
|
||||
@@ -8664,6 +8812,12 @@ namespace ts {
|
||||
if (type.flags & TypeFlags.IndexedAccess) {
|
||||
return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper));
|
||||
}
|
||||
if (type.flags & TypeFlags.Conditional) {
|
||||
return getConditionalTypeInstantiation(<ConditionalType>type, mapper);
|
||||
}
|
||||
if (type.flags & TypeFlags.Substitution) {
|
||||
return mapper((<SubstitutionType>type).typeParameter);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
@@ -8785,7 +8939,7 @@ namespace ts {
|
||||
function isTypeDerivedFrom(source: Type, target: Type): boolean {
|
||||
return source.flags & TypeFlags.Union ? every((<UnionType>source).types, t => isTypeDerivedFrom(t, target)) :
|
||||
target.flags & TypeFlags.Union ? some((<UnionType>target).types, t => isTypeDerivedFrom(source, t)) :
|
||||
source.flags & TypeFlags.TypeVariable ? isTypeDerivedFrom(getBaseConstraintOfType(source) || emptyObjectType, target) :
|
||||
source.flags & TypeFlags.InstantiableNonPrimitive ? isTypeDerivedFrom(getBaseConstraintOfType(source) || emptyObjectType, target) :
|
||||
target === globalObjectType || target === globalFunctionType ? isTypeSubtypeOf(source, target) :
|
||||
hasBaseType(source, getTargetType(target));
|
||||
}
|
||||
@@ -9124,14 +9278,14 @@ namespace ts {
|
||||
return related === RelationComparisonResult.Succeeded;
|
||||
}
|
||||
}
|
||||
if (source.flags & TypeFlags.StructuredOrTypeVariable || target.flags & TypeFlags.StructuredOrTypeVariable) {
|
||||
if (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable) {
|
||||
return checkTypeRelatedTo(source, target, relation, /*errorNode*/ undefined);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9263,6 +9417,13 @@ namespace ts {
|
||||
if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) {
|
||||
target = (<LiteralType>target).regularType;
|
||||
}
|
||||
if (source.flags & TypeFlags.Substitution) {
|
||||
source = (<SubstitutionType>source).substitute;
|
||||
}
|
||||
if (target.flags & TypeFlags.Substitution) {
|
||||
target = (<SubstitutionType>target).typeParameter;
|
||||
}
|
||||
|
||||
// both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
|
||||
if (source === target) return Ternary.True;
|
||||
|
||||
@@ -9349,7 +9510,7 @@ namespace ts {
|
||||
// breaking the intersection apart.
|
||||
result = someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false);
|
||||
}
|
||||
if (!result && (source.flags & TypeFlags.StructuredOrTypeVariable || target.flags & TypeFlags.StructuredOrTypeVariable)) {
|
||||
if (!result && (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable)) {
|
||||
if (result = recursiveTypeRelatedTo(source, target, reportErrors)) {
|
||||
errorInfo = saveErrorInfo;
|
||||
}
|
||||
@@ -9388,7 +9549,7 @@ namespace ts {
|
||||
|
||||
function hasExcessProperties(source: FreshObjectLiteralType, target: Type, discriminant: Type | undefined, reportErrors: boolean): boolean {
|
||||
if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) {
|
||||
const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes);
|
||||
const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
|
||||
if ((relation === assignableRelation || relation === comparableRelation) &&
|
||||
(isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) {
|
||||
return false;
|
||||
@@ -9701,13 +9862,21 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isGenericMappedType(target) && !isGenericMappedType(source) && getConstraintTypeFromMappedType(<MappedType>target) === getIndexType(source)) {
|
||||
else if (isGenericMappedType(target)) {
|
||||
// A source type T is related to a target type { [P in X]: T[P] }
|
||||
const template = getTemplateTypeFromMappedType(<MappedType>target);
|
||||
if (template.flags & TypeFlags.IndexedAccess && (<IndexedAccessType>template).objectType === source &&
|
||||
(<IndexedAccessType>template).indexType === getTypeParameterFromMappedType(<MappedType>target)) {
|
||||
return Ternary.True;
|
||||
}
|
||||
// A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X.
|
||||
const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(<MappedType>target));
|
||||
const templateType = getTemplateTypeFromMappedType(<MappedType>target);
|
||||
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
|
||||
errorInfo = saveErrorInfo;
|
||||
return result;
|
||||
if (!isGenericMappedType(source) && getConstraintTypeFromMappedType(<MappedType>target) === getIndexType(source)) {
|
||||
const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(<MappedType>target));
|
||||
const templateType = getTemplateTypeFromMappedType(<MappedType>target);
|
||||
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
|
||||
errorInfo = saveErrorInfo;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9746,9 +9915,22 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (source.flags & TypeFlags.Conditional) {
|
||||
const constraint = getConstraintOfDistributiveConditionalType(<ConditionalType>source);
|
||||
if (constraint) {
|
||||
if (result = isRelatedTo(constraint, target, reportErrors)) {
|
||||
errorInfo = saveErrorInfo;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (result = isRelatedTo(getDefaultConstraintOfConditionalType(<ConditionalType>source), target, reportErrors)) {
|
||||
errorInfo = saveErrorInfo;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target &&
|
||||
!(source.flags & TypeFlags.MarkerType || target.flags & TypeFlags.MarkerType)) {
|
||||
!(getObjectFlags(source) & ObjectFlags.MarkerType || getObjectFlags(target) & ObjectFlags.MarkerType)) {
|
||||
// We have type references to the same generic type, and the type references are not marker
|
||||
// type references (which are intended by be compared structurally). Obtain the variance
|
||||
// information for the type parameters and relate the type arguments accordingly.
|
||||
@@ -9965,7 +10147,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function hasCommonProperties(source: Type, target: Type) {
|
||||
const isComparingJsxAttributes = !!(source.flags & TypeFlags.JsxAttributes);
|
||||
const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
|
||||
for (const prop of getPropertiesOfType(source)) {
|
||||
if (isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
|
||||
return true;
|
||||
@@ -10212,7 +10394,7 @@ namespace ts {
|
||||
// type, and flag the result as a marker type reference.
|
||||
function getMarkerTypeReference(type: GenericType, source: TypeParameter, target: Type) {
|
||||
const result = createTypeReference(type, map(type.typeParameters, t => t === source ? target : t));
|
||||
result.flags |= TypeFlags.MarkerType;
|
||||
result.objectFlags |= ObjectFlags.MarkerType;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11003,7 +11185,7 @@ namespace ts {
|
||||
// results for union and intersection types for performance reasons.
|
||||
function couldContainTypeVariables(type: Type): boolean {
|
||||
const objectFlags = getObjectFlags(type);
|
||||
return !!(type.flags & (TypeFlags.TypeVariable | TypeFlags.Index) ||
|
||||
return !!(type.flags & TypeFlags.Instantiable ||
|
||||
objectFlags & ObjectFlags.Reference && forEach((<TypeReference>type).typeArguments, couldContainTypeVariables) ||
|
||||
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) ||
|
||||
objectFlags & ObjectFlags.Mapped ||
|
||||
@@ -11224,14 +11406,20 @@ namespace ts {
|
||||
inferFromTypes((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType);
|
||||
inferFromTypes((<IndexedAccessType>source).indexType, (<IndexedAccessType>target).indexType);
|
||||
}
|
||||
else if (source.flags & TypeFlags.Conditional && target.flags & TypeFlags.Conditional) {
|
||||
inferFromTypes((<ConditionalType>source).checkType, (<ConditionalType>target).checkType);
|
||||
inferFromTypes((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType);
|
||||
inferFromTypes((<ConditionalType>source).trueType, (<ConditionalType>target).trueType);
|
||||
inferFromTypes((<ConditionalType>source).falseType, (<ConditionalType>target).falseType);
|
||||
}
|
||||
else if (target.flags & TypeFlags.UnionOrIntersection) {
|
||||
const targetTypes = (<UnionOrIntersectionType>target).types;
|
||||
let typeVariableCount = 0;
|
||||
let typeVariable: TypeVariable;
|
||||
let typeVariable: TypeParameter | IndexedAccessType;
|
||||
// First infer to each type in union or intersection that isn't a type variable
|
||||
for (const t of targetTypes) {
|
||||
if (getInferenceInfoForType(t)) {
|
||||
typeVariable = <TypeVariable>t;
|
||||
typeVariable = <InstantiableType>t;
|
||||
typeVariableCount++;
|
||||
}
|
||||
else {
|
||||
@@ -11813,7 +12001,7 @@ namespace ts {
|
||||
if (flags & TypeFlags.NonPrimitive) {
|
||||
return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts;
|
||||
}
|
||||
if (flags & TypeFlags.TypeVariable) {
|
||||
if (flags & TypeFlags.Instantiable) {
|
||||
return getTypeFacts(getBaseConstraintOfType(type) || emptyObjectType);
|
||||
}
|
||||
if (flags & TypeFlags.UnionOrIntersection) {
|
||||
@@ -12677,7 +12865,7 @@ namespace ts {
|
||||
if (isTypeSubtypeOf(targetType, type)) {
|
||||
return targetType;
|
||||
}
|
||||
if (type.flags & TypeFlags.TypeVariable) {
|
||||
if (type.flags & TypeFlags.Instantiable) {
|
||||
const constraint = getBaseConstraintOfType(type) || anyType;
|
||||
if (isTypeSubtypeOf(targetType, constraint)) {
|
||||
return getIntersectionType([type, targetType]);
|
||||
@@ -12942,7 +13130,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function typeHasNullableConstraint(type: Type) {
|
||||
return type.flags & TypeFlags.TypeVariable && maybeTypeOfKind(getBaseConstraintOfType(type) || emptyObjectType, TypeFlags.Nullable);
|
||||
return type.flags & TypeFlags.InstantiableNonPrimitive && maybeTypeOfKind(getBaseConstraintOfType(type) || emptyObjectType, TypeFlags.Nullable);
|
||||
}
|
||||
|
||||
function getApparentTypeForLocation(type: Type, node: Node) {
|
||||
@@ -14472,7 +14660,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, /*objectFlags*/ 0);
|
||||
propertiesArray = [];
|
||||
propertiesTable = createSymbolTable();
|
||||
hasComputedStringProperty = false;
|
||||
@@ -14484,7 +14672,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, /*objectFlags*/ 0);
|
||||
offset = i + 1;
|
||||
continue;
|
||||
}
|
||||
@@ -14529,7 +14717,7 @@ namespace ts {
|
||||
|
||||
if (spread !== emptyObjectType) {
|
||||
if (propertiesArray.length > 0) {
|
||||
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags);
|
||||
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, /*objectFlags*/ 0);
|
||||
}
|
||||
return spread;
|
||||
}
|
||||
@@ -14662,7 +14850,7 @@ 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, /*typeFlags*/ 0, ObjectFlags.JsxAttributes);
|
||||
attributesTable = createSymbolTable();
|
||||
}
|
||||
const exprType = checkExpressionCached(attributeDecl.expression, checkMode);
|
||||
@@ -14670,7 +14858,7 @@ namespace ts {
|
||||
hasSpreadAnyType = true;
|
||||
}
|
||||
if (isValidSpreadType(exprType)) {
|
||||
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, TypeFlags.JsxAttributes);
|
||||
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, /*typeFlags*/ 0, ObjectFlags.JsxAttributes);
|
||||
}
|
||||
else {
|
||||
typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
|
||||
@@ -14680,7 +14868,7 @@ namespace ts {
|
||||
|
||||
if (!hasSpreadAnyType) {
|
||||
if (attributesTable.size > 0) {
|
||||
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, TypeFlags.JsxAttributes);
|
||||
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, /*typeFlags*/ 0, ObjectFlags.JsxAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14705,7 +14893,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, /*typeFlags*/ 0, ObjectFlags.JsxAttributes);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14722,8 +14911,8 @@ namespace ts {
|
||||
*/
|
||||
function createJsxAttributesType() {
|
||||
const result = createAnonymousType(attributes.symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
|
||||
result.flags |= TypeFlags.JsxAttributes | TypeFlags.ContainsObjectLiteral;
|
||||
result.objectFlags |= ObjectFlags.ObjectLiteral;
|
||||
result.flags |= TypeFlags.ContainsObjectLiteral;
|
||||
result.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.JsxAttributes;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -17610,7 +17799,7 @@ namespace ts {
|
||||
const anonymousSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type);
|
||||
const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
|
||||
anonymousSymbol.type = defaultContainingObject;
|
||||
synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*propegatedFlags*/ 0) : defaultContainingObject;
|
||||
synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*typeFLags*/ 0, /*objectFlags*/ 0) : defaultContainingObject;
|
||||
}
|
||||
else {
|
||||
synthType.syntheticType = type;
|
||||
@@ -18337,7 +18526,7 @@ namespace ts {
|
||||
// Return true if type might be of the given kind. A union or intersection type might be of a given
|
||||
// kind if at least one constituent type is of the given kind.
|
||||
function maybeTypeOfKind(type: Type, kind: TypeFlags): boolean {
|
||||
if (type.flags & kind) {
|
||||
if (type.flags & kind || kind & TypeFlags.GenericMappedType && isGenericMappedType(type)) {
|
||||
return true;
|
||||
}
|
||||
if (type.flags & TypeFlags.UnionOrIntersection) {
|
||||
@@ -18416,7 +18605,7 @@ namespace ts {
|
||||
if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, TypeFlags.NumberLike | TypeFlags.ESSymbolLike))) {
|
||||
error(left, Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
|
||||
}
|
||||
if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) {
|
||||
if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) {
|
||||
error(right, Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
||||
}
|
||||
return booleanType;
|
||||
@@ -19015,7 +19204,7 @@ namespace ts {
|
||||
const types = (<UnionType>contextualType).types;
|
||||
return some(types, t => isLiteralOfContextualType(candidateType, t));
|
||||
}
|
||||
if (contextualType.flags & TypeFlags.TypeVariable) {
|
||||
if (contextualType.flags & TypeFlags.InstantiableNonPrimitive) {
|
||||
// If the contextual type is a type variable constrained to a primitive type, consider
|
||||
// this a literal context for literals of that primitive type. For example, given a
|
||||
// type parameter 'T extends string', infer string literal types for T.
|
||||
@@ -19981,6 +20170,10 @@ namespace ts {
|
||||
checkSourceElement(node.type);
|
||||
}
|
||||
|
||||
function checkConditionalType(node: ConditionalTypeNode) {
|
||||
forEachChild(node, checkSourceElement);
|
||||
}
|
||||
|
||||
function isPrivateWithinAmbient(node: Node): boolean {
|
||||
return hasModifier(node, ModifierFlags.Private) && !!(node.flags & NodeFlags.Ambient);
|
||||
}
|
||||
@@ -21768,7 +21961,7 @@ namespace ts {
|
||||
|
||||
// unknownType is returned i.e. if node.expression is identifier whose name cannot be resolved
|
||||
// in this case error about missing name is already reported - do not report extra one
|
||||
if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.TypeVariable)) {
|
||||
if (!isTypeAssignableToKind(rightType, TypeFlags.NonPrimitive | TypeFlags.InstantiableNonPrimitive)) {
|
||||
error(node.expression, Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
||||
}
|
||||
|
||||
@@ -23690,6 +23883,8 @@ namespace ts {
|
||||
return checkSourceElement((<ParenthesizedTypeNode | TypeOperatorNode>node).type);
|
||||
case SyntaxKind.TypeOperator:
|
||||
return checkTypeOperator(<TypeOperatorNode>node);
|
||||
case SyntaxKind.ConditionalType:
|
||||
return checkConditionalType(<ConditionalTypeNode>node);
|
||||
case SyntaxKind.JSDocAugmentsTag:
|
||||
return checkJSDocAugmentsTag(node as JSDocAugmentsTag);
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
|
||||
+9
-11
@@ -439,23 +439,21 @@ namespace ts {
|
||||
export function sameMap<T>(array: T[], f: (x: T, i: number) => T): T[];
|
||||
export function sameMap<T>(array: ReadonlyArray<T>, f: (x: T, i: number) => T): ReadonlyArray<T>;
|
||||
export function sameMap<T>(array: T[], f: (x: T, i: number) => T): T[] {
|
||||
let result: T[];
|
||||
if (array) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (result) {
|
||||
result.push(f(array[i], i));
|
||||
}
|
||||
else {
|
||||
const item = array[i];
|
||||
const mapped = f(item, i);
|
||||
if (item !== mapped) {
|
||||
result = array.slice(0, i);
|
||||
result.push(mapped);
|
||||
const item = array[i];
|
||||
const mapped = f(item, i);
|
||||
if (item !== mapped) {
|
||||
const result = array.slice(0, i);
|
||||
result.push(mapped);
|
||||
for (i++; i < array.length; i++) {
|
||||
result.push(f(array[i], i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result || array;
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -450,6 +450,8 @@ namespace ts {
|
||||
return emitUnionType(<UnionTypeNode>type);
|
||||
case SyntaxKind.IntersectionType:
|
||||
return emitIntersectionType(<IntersectionTypeNode>type);
|
||||
case SyntaxKind.ConditionalType:
|
||||
return emitConditionalType(<ConditionalTypeNode>type);
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
return emitParenType(<ParenthesizedTypeNode>type);
|
||||
case SyntaxKind.TypeOperator:
|
||||
@@ -545,6 +547,16 @@ namespace ts {
|
||||
emitSeparatedList(type.types, " & ", emitType);
|
||||
}
|
||||
|
||||
function emitConditionalType(node: ConditionalTypeNode) {
|
||||
emitType(node.checkType);
|
||||
write(" extends ");
|
||||
emitType(node.extendsType);
|
||||
write(" ? ");
|
||||
emitType(node.trueType);
|
||||
write(" : ");
|
||||
emitType(node.falseType);
|
||||
}
|
||||
|
||||
function emitParenType(type: ParenthesizedTypeNode) {
|
||||
write("(");
|
||||
emitType(type.type);
|
||||
|
||||
@@ -600,6 +600,8 @@ namespace ts {
|
||||
return emitUnionType(<UnionTypeNode>node);
|
||||
case SyntaxKind.IntersectionType:
|
||||
return emitIntersectionType(<IntersectionTypeNode>node);
|
||||
case SyntaxKind.ConditionalType:
|
||||
return emitConditionalType(<ConditionalTypeNode>node);
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
return emitParenthesizedType(<ParenthesizedTypeNode>node);
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
@@ -1190,6 +1192,16 @@ namespace ts {
|
||||
emitList(node, node.types, ListFormat.IntersectionTypeConstituents);
|
||||
}
|
||||
|
||||
function emitConditionalType(node: ConditionalTypeNode) {
|
||||
emit(node.checkType);
|
||||
write(" extends ");
|
||||
emit(node.extendsType);
|
||||
write(" ? ");
|
||||
emit(node.trueType);
|
||||
write(" : ");
|
||||
emit(node.falseType);
|
||||
}
|
||||
|
||||
function emitParenthesizedType(node: ParenthesizedTypeNode) {
|
||||
writePunctuation("(");
|
||||
emit(node.type);
|
||||
|
||||
+23
-1
@@ -731,6 +731,24 @@ namespace ts {
|
||||
: node;
|
||||
}
|
||||
|
||||
export function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode) {
|
||||
const node = createSynthesizedNode(SyntaxKind.ConditionalType) as ConditionalTypeNode;
|
||||
node.checkType = parenthesizeConditionalTypeMember(checkType);
|
||||
node.extendsType = parenthesizeConditionalTypeMember(extendsType);
|
||||
node.trueType = trueType;
|
||||
node.falseType = falseType;
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode) {
|
||||
return node.checkType !== checkType
|
||||
|| node.extendsType !== extendsType
|
||||
|| node.trueType !== trueType
|
||||
|| node.falseType !== falseType
|
||||
? updateNode(createConditionalTypeNode(checkType, extendsType, trueType, falseType), node)
|
||||
: node;
|
||||
}
|
||||
|
||||
export function createParenthesizedType(type: TypeNode) {
|
||||
const node = <ParenthesizedTypeNode>createSynthesizedNode(SyntaxKind.ParenthesizedType);
|
||||
node.type = type;
|
||||
@@ -4094,6 +4112,10 @@ namespace ts {
|
||||
return expression;
|
||||
}
|
||||
|
||||
export function parenthesizeConditionalTypeMember(member: TypeNode) {
|
||||
return member.kind === SyntaxKind.ConditionalType ? createParenthesizedType(member) : member;
|
||||
}
|
||||
|
||||
export function parenthesizeElementTypeMember(member: TypeNode) {
|
||||
switch (member.kind) {
|
||||
case SyntaxKind.UnionType:
|
||||
@@ -4102,7 +4124,7 @@ namespace ts {
|
||||
case SyntaxKind.ConstructorType:
|
||||
return createParenthesizedType(member);
|
||||
}
|
||||
return member;
|
||||
return parenthesizeConditionalTypeMember(member);
|
||||
}
|
||||
|
||||
export function parenthesizeArrayTypeMember(member: TypeNode) {
|
||||
|
||||
+28
-2
@@ -175,6 +175,11 @@ namespace ts {
|
||||
case SyntaxKind.UnionType:
|
||||
case SyntaxKind.IntersectionType:
|
||||
return visitNodes(cbNode, cbNodes, (<UnionOrIntersectionTypeNode>node).types);
|
||||
case SyntaxKind.ConditionalType:
|
||||
return visitNode(cbNode, (<ConditionalTypeNode>node).checkType) ||
|
||||
visitNode(cbNode, (<ConditionalTypeNode>node).extendsType) ||
|
||||
visitNode(cbNode, (<ConditionalTypeNode>node).trueType) ||
|
||||
visitNode(cbNode, (<ConditionalTypeNode>node).falseType);
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
case SyntaxKind.TypeOperator:
|
||||
return visitNode(cbNode, (<ParenthesizedTypeNode | TypeOperatorNode>node).type);
|
||||
@@ -1494,6 +1499,11 @@ namespace ts {
|
||||
return isStartOfExpression();
|
||||
}
|
||||
|
||||
function nextTokenIsStartOfType() {
|
||||
nextToken();
|
||||
return isStartOfType();
|
||||
}
|
||||
|
||||
// True if positioned at a list terminator
|
||||
function isListTerminator(kind: ParsingContext): boolean {
|
||||
if (token() === SyntaxKind.EndOfFileToken) {
|
||||
@@ -2789,6 +2799,10 @@ namespace ts {
|
||||
type = createJSDocPostfixType(SyntaxKind.JSDocNonNullableType, type);
|
||||
break;
|
||||
case SyntaxKind.QuestionToken:
|
||||
// If not in JSDoc and next token is start of a type we have a conditional type
|
||||
if (!(contextFlags & NodeFlags.JSDoc) && lookAhead(nextTokenIsStartOfType)) {
|
||||
return type;
|
||||
}
|
||||
type = createJSDocPostfixType(SyntaxKind.JSDocNullableType, type);
|
||||
break;
|
||||
case SyntaxKind.OpenBracketToken:
|
||||
@@ -2950,14 +2964,26 @@ namespace ts {
|
||||
return doOutsideOfContext(NodeFlags.TypeExcludesFlags, parseTypeWorker);
|
||||
}
|
||||
|
||||
function parseTypeWorker(): TypeNode {
|
||||
function parseTypeWorker(noConditionalTypes?: boolean): TypeNode {
|
||||
if (isStartOfFunctionType()) {
|
||||
return parseFunctionOrConstructorType(SyntaxKind.FunctionType);
|
||||
}
|
||||
if (token() === SyntaxKind.NewKeyword) {
|
||||
return parseFunctionOrConstructorType(SyntaxKind.ConstructorType);
|
||||
}
|
||||
return parseUnionTypeOrHigher();
|
||||
const type = parseUnionTypeOrHigher();
|
||||
if (!noConditionalTypes && parseOptional(SyntaxKind.ExtendsKeyword)) {
|
||||
const node = <ConditionalTypeNode>createNode(SyntaxKind.ConditionalType, type.pos);
|
||||
node.checkType = type;
|
||||
// The type following 'extends' is not permitted to be another conditional type
|
||||
node.extendsType = parseTypeWorker(/*noConditionalTypes*/ true);
|
||||
parseExpected(SyntaxKind.QuestionToken);
|
||||
node.trueType = parseTypeWorker();
|
||||
parseExpected(SyntaxKind.ColonToken);
|
||||
node.falseType = parseTypeWorker();
|
||||
return finishNode(node);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
function parseTypeAnnotation(): TypeNode {
|
||||
|
||||
@@ -385,6 +385,7 @@ namespace ts {
|
||||
case SyntaxKind.TypeReference:
|
||||
case SyntaxKind.UnionType:
|
||||
case SyntaxKind.IntersectionType:
|
||||
case SyntaxKind.ConditionalType:
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
case SyntaxKind.ThisType:
|
||||
case SyntaxKind.TypeOperator:
|
||||
|
||||
+54
-15
@@ -265,6 +265,7 @@ namespace ts {
|
||||
TupleType,
|
||||
UnionType,
|
||||
IntersectionType,
|
||||
ConditionalType,
|
||||
ParenthesizedType,
|
||||
ThisType,
|
||||
TypeOperator,
|
||||
@@ -1116,6 +1117,14 @@ namespace ts {
|
||||
types: NodeArray<TypeNode>;
|
||||
}
|
||||
|
||||
export interface ConditionalTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.ConditionalType;
|
||||
checkType: TypeNode;
|
||||
extendsType: TypeNode;
|
||||
trueType: TypeNode;
|
||||
falseType: TypeNode;
|
||||
}
|
||||
|
||||
export interface ParenthesizedTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.ParenthesizedType;
|
||||
type: TypeNode;
|
||||
@@ -3484,18 +3493,19 @@ namespace ts {
|
||||
Intersection = 1 << 18, // Intersection (T & U)
|
||||
Index = 1 << 19, // keyof T
|
||||
IndexedAccess = 1 << 20, // T[K]
|
||||
Conditional = 1 << 21, // T extends U ? X : Y
|
||||
Substitution = 1 << 22, // Type parameter substitution
|
||||
/* @internal */
|
||||
FreshLiteral = 1 << 21, // Fresh literal or unique type
|
||||
FreshLiteral = 1 << 23, // Fresh literal or unique type
|
||||
/* @internal */
|
||||
ContainsWideningType = 1 << 22, // Type is or contains undefined or null widening type
|
||||
ContainsWideningType = 1 << 24, // Type is or contains undefined or null widening type
|
||||
/* @internal */
|
||||
ContainsObjectLiteral = 1 << 23, // Type is or contains object literal type
|
||||
ContainsObjectLiteral = 1 << 25, // Type is or contains object literal type
|
||||
/* @internal */
|
||||
ContainsAnyFunctionType = 1 << 24, // Type is or contains the anyFunctionType
|
||||
NonPrimitive = 1 << 25, // intrinsic object type
|
||||
ContainsAnyFunctionType = 1 << 26, // Type is or contains the anyFunctionType
|
||||
NonPrimitive = 1 << 27, // intrinsic object type
|
||||
/* @internal */
|
||||
JsxAttributes = 1 << 26, // Jsx attributes type
|
||||
MarkerType = 1 << 27, // Marker type used for variance probing
|
||||
GenericMappedType = 1 << 29, // Flag used by maybeTypeOfKind
|
||||
|
||||
/* @internal */
|
||||
Nullable = Undefined | Null,
|
||||
@@ -3518,17 +3528,21 @@ namespace ts {
|
||||
ESSymbolLike = ESSymbol | UniqueESSymbol,
|
||||
UnionOrIntersection = Union | Intersection,
|
||||
StructuredType = Object | Union | Intersection,
|
||||
StructuredOrTypeVariable = StructuredType | TypeParameter | Index | IndexedAccess,
|
||||
TypeVariable = TypeParameter | IndexedAccess,
|
||||
InstantiableNonPrimitive = TypeVariable | Conditional | Substitution,
|
||||
InstantiablePrimitive = Index,
|
||||
Instantiable = InstantiableNonPrimitive | InstantiablePrimitive,
|
||||
StructuredOrInstantiable = StructuredType | Instantiable,
|
||||
|
||||
// 'Narrowable' types are types where narrowing actually narrows.
|
||||
// This *should* be every type other than null, undefined, void, and never
|
||||
Narrowable = Any | StructuredType | TypeParameter | Index | IndexedAccess | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
|
||||
Narrowable = Any | StructuredOrInstantiable | StringLike | NumberLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
|
||||
NotUnionOrUnit = Any | ESSymbol | Object | NonPrimitive,
|
||||
/* @internal */
|
||||
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
|
||||
/* @internal */
|
||||
PropagatingFlags = ContainsWideningType | ContainsObjectLiteral | ContainsAnyFunctionType,
|
||||
/* @internal */
|
||||
}
|
||||
|
||||
export type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
|
||||
@@ -3587,7 +3601,9 @@ namespace ts {
|
||||
EvolvingArray = 1 << 8, // Evolving array type
|
||||
ObjectLiteralPatternWithComputedProperties = 1 << 9, // Object literal pattern with computed properties
|
||||
ContainsSpread = 1 << 10, // Object literal contains spread operation
|
||||
ReverseMapped = 1 << 11, // Object contains a property from a reverse-mapped type
|
||||
ReverseMapped = 1 << 11, // Object contains a property from a reverse-mapped type
|
||||
JsxAttributes = 1 << 12, // Jsx attributes type
|
||||
MarkerType = 1 << 13, // Marker type used for variance probing
|
||||
ClassOrInterface = Class | Interface
|
||||
}
|
||||
|
||||
@@ -3741,7 +3757,7 @@ namespace ts {
|
||||
syntheticType?: Type;
|
||||
}
|
||||
|
||||
export interface TypeVariable extends Type {
|
||||
export interface InstantiableType extends Type {
|
||||
/* @internal */
|
||||
resolvedBaseConstraint?: Type;
|
||||
/* @internal */
|
||||
@@ -3749,7 +3765,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Type parameters (TypeFlags.TypeParameter)
|
||||
export interface TypeParameter extends TypeVariable {
|
||||
export interface TypeParameter extends InstantiableType {
|
||||
/** Retrieve using getConstraintFromTypeParameter */
|
||||
/* @internal */
|
||||
constraint?: Type; // Constraint
|
||||
@@ -3767,15 +3783,38 @@ namespace ts {
|
||||
|
||||
// Indexed access types (TypeFlags.IndexedAccess)
|
||||
// Possible forms are T[xxx], xxx[T], or xxx[keyof T], where T is a type variable
|
||||
export interface IndexedAccessType extends TypeVariable {
|
||||
export interface IndexedAccessType extends InstantiableType {
|
||||
objectType: Type;
|
||||
indexType: Type;
|
||||
constraint?: Type;
|
||||
}
|
||||
|
||||
// keyof T types (TypeFlags.Index)
|
||||
export interface IndexType extends Type {
|
||||
type: TypeVariable | UnionOrIntersectionType;
|
||||
export interface IndexType extends InstantiableType {
|
||||
type: InstantiableType | UnionOrIntersectionType;
|
||||
}
|
||||
|
||||
// T extends U ? X : Y (TypeFlags.Conditional)
|
||||
export interface ConditionalType extends InstantiableType {
|
||||
checkType: Type;
|
||||
extendsType: Type;
|
||||
trueType: Type;
|
||||
falseType: Type;
|
||||
/* @internal */
|
||||
target?: ConditionalType;
|
||||
/* @internal */
|
||||
mapper?: TypeMapper;
|
||||
}
|
||||
|
||||
// Type parameter substitution (TypeFlags.Substitution)
|
||||
// Substitution types are created for type parameter references that occur in the true branch
|
||||
// of a conditional type. For example, in 'T extends string ? Foo<T> : Bar<T>', the reference to
|
||||
// T in Foo<T> is resolved as a substitution type that substitutes 'string & T' for T. Thus, if
|
||||
// Foo has a 'string' constraint on its type parameter, T will satisfy it. Substitution types
|
||||
// disappear upon instantiation (just like type parameters).
|
||||
export interface SubstitutionType extends InstantiableType {
|
||||
typeParameter: TypeParameter; // Target type parameter
|
||||
substitute: Type; // Type to substitute for type parameter
|
||||
}
|
||||
|
||||
export const enum SignatureKind {
|
||||
|
||||
@@ -4621,6 +4621,10 @@ namespace ts {
|
||||
return node.kind === SyntaxKind.IntersectionType;
|
||||
}
|
||||
|
||||
export function isConditionalTypeNode(node: Node): node is ConditionalTypeNode {
|
||||
return node.kind === SyntaxKind.ConditionalType;
|
||||
}
|
||||
|
||||
export function isParenthesizedTypeNode(node: Node): node is ParenthesizedTypeNode {
|
||||
return node.kind === SyntaxKind.ParenthesizedType;
|
||||
}
|
||||
|
||||
@@ -387,6 +387,13 @@ namespace ts {
|
||||
return updateIntersectionTypeNode(<IntersectionTypeNode>node,
|
||||
nodesVisitor((<IntersectionTypeNode>node).types, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.ConditionalType:
|
||||
return updateConditionalTypeNode(<ConditionalTypeNode>node,
|
||||
visitNode((<ConditionalTypeNode>node).checkType, visitor, isTypeNode),
|
||||
visitNode((<ConditionalTypeNode>node).extendsType, visitor, isTypeNode),
|
||||
visitNode((<ConditionalTypeNode>node).trueType, visitor, isTypeNode),
|
||||
visitNode((<ConditionalTypeNode>node).falseType, visitor, isTypeNode));
|
||||
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
return updateParenthesizedType(<ParenthesizedTypeNode>node,
|
||||
visitNode((<ParenthesizedTypeNode>node).type, visitor, isTypeNode));
|
||||
|
||||
+170
-143
@@ -230,134 +230,135 @@ declare namespace ts {
|
||||
TupleType = 166,
|
||||
UnionType = 167,
|
||||
IntersectionType = 168,
|
||||
ParenthesizedType = 169,
|
||||
ThisType = 170,
|
||||
TypeOperator = 171,
|
||||
IndexedAccessType = 172,
|
||||
MappedType = 173,
|
||||
LiteralType = 174,
|
||||
ObjectBindingPattern = 175,
|
||||
ArrayBindingPattern = 176,
|
||||
BindingElement = 177,
|
||||
ArrayLiteralExpression = 178,
|
||||
ObjectLiteralExpression = 179,
|
||||
PropertyAccessExpression = 180,
|
||||
ElementAccessExpression = 181,
|
||||
CallExpression = 182,
|
||||
NewExpression = 183,
|
||||
TaggedTemplateExpression = 184,
|
||||
TypeAssertionExpression = 185,
|
||||
ParenthesizedExpression = 186,
|
||||
FunctionExpression = 187,
|
||||
ArrowFunction = 188,
|
||||
DeleteExpression = 189,
|
||||
TypeOfExpression = 190,
|
||||
VoidExpression = 191,
|
||||
AwaitExpression = 192,
|
||||
PrefixUnaryExpression = 193,
|
||||
PostfixUnaryExpression = 194,
|
||||
BinaryExpression = 195,
|
||||
ConditionalExpression = 196,
|
||||
TemplateExpression = 197,
|
||||
YieldExpression = 198,
|
||||
SpreadElement = 199,
|
||||
ClassExpression = 200,
|
||||
OmittedExpression = 201,
|
||||
ExpressionWithTypeArguments = 202,
|
||||
AsExpression = 203,
|
||||
NonNullExpression = 204,
|
||||
MetaProperty = 205,
|
||||
TemplateSpan = 206,
|
||||
SemicolonClassElement = 207,
|
||||
Block = 208,
|
||||
VariableStatement = 209,
|
||||
EmptyStatement = 210,
|
||||
ExpressionStatement = 211,
|
||||
IfStatement = 212,
|
||||
DoStatement = 213,
|
||||
WhileStatement = 214,
|
||||
ForStatement = 215,
|
||||
ForInStatement = 216,
|
||||
ForOfStatement = 217,
|
||||
ContinueStatement = 218,
|
||||
BreakStatement = 219,
|
||||
ReturnStatement = 220,
|
||||
WithStatement = 221,
|
||||
SwitchStatement = 222,
|
||||
LabeledStatement = 223,
|
||||
ThrowStatement = 224,
|
||||
TryStatement = 225,
|
||||
DebuggerStatement = 226,
|
||||
VariableDeclaration = 227,
|
||||
VariableDeclarationList = 228,
|
||||
FunctionDeclaration = 229,
|
||||
ClassDeclaration = 230,
|
||||
InterfaceDeclaration = 231,
|
||||
TypeAliasDeclaration = 232,
|
||||
EnumDeclaration = 233,
|
||||
ModuleDeclaration = 234,
|
||||
ModuleBlock = 235,
|
||||
CaseBlock = 236,
|
||||
NamespaceExportDeclaration = 237,
|
||||
ImportEqualsDeclaration = 238,
|
||||
ImportDeclaration = 239,
|
||||
ImportClause = 240,
|
||||
NamespaceImport = 241,
|
||||
NamedImports = 242,
|
||||
ImportSpecifier = 243,
|
||||
ExportAssignment = 244,
|
||||
ExportDeclaration = 245,
|
||||
NamedExports = 246,
|
||||
ExportSpecifier = 247,
|
||||
MissingDeclaration = 248,
|
||||
ExternalModuleReference = 249,
|
||||
JsxElement = 250,
|
||||
JsxSelfClosingElement = 251,
|
||||
JsxOpeningElement = 252,
|
||||
JsxClosingElement = 253,
|
||||
JsxFragment = 254,
|
||||
JsxOpeningFragment = 255,
|
||||
JsxClosingFragment = 256,
|
||||
JsxAttribute = 257,
|
||||
JsxAttributes = 258,
|
||||
JsxSpreadAttribute = 259,
|
||||
JsxExpression = 260,
|
||||
CaseClause = 261,
|
||||
DefaultClause = 262,
|
||||
HeritageClause = 263,
|
||||
CatchClause = 264,
|
||||
PropertyAssignment = 265,
|
||||
ShorthandPropertyAssignment = 266,
|
||||
SpreadAssignment = 267,
|
||||
EnumMember = 268,
|
||||
SourceFile = 269,
|
||||
Bundle = 270,
|
||||
JSDocTypeExpression = 271,
|
||||
JSDocAllType = 272,
|
||||
JSDocUnknownType = 273,
|
||||
JSDocNullableType = 274,
|
||||
JSDocNonNullableType = 275,
|
||||
JSDocOptionalType = 276,
|
||||
JSDocFunctionType = 277,
|
||||
JSDocVariadicType = 278,
|
||||
JSDocComment = 279,
|
||||
JSDocTypeLiteral = 280,
|
||||
JSDocTag = 281,
|
||||
JSDocAugmentsTag = 282,
|
||||
JSDocClassTag = 283,
|
||||
JSDocParameterTag = 284,
|
||||
JSDocReturnTag = 285,
|
||||
JSDocTypeTag = 286,
|
||||
JSDocTemplateTag = 287,
|
||||
JSDocTypedefTag = 288,
|
||||
JSDocPropertyTag = 289,
|
||||
SyntaxList = 290,
|
||||
NotEmittedStatement = 291,
|
||||
PartiallyEmittedExpression = 292,
|
||||
CommaListExpression = 293,
|
||||
MergeDeclarationMarker = 294,
|
||||
EndOfDeclarationMarker = 295,
|
||||
Count = 296,
|
||||
ConditionalType = 169,
|
||||
ParenthesizedType = 170,
|
||||
ThisType = 171,
|
||||
TypeOperator = 172,
|
||||
IndexedAccessType = 173,
|
||||
MappedType = 174,
|
||||
LiteralType = 175,
|
||||
ObjectBindingPattern = 176,
|
||||
ArrayBindingPattern = 177,
|
||||
BindingElement = 178,
|
||||
ArrayLiteralExpression = 179,
|
||||
ObjectLiteralExpression = 180,
|
||||
PropertyAccessExpression = 181,
|
||||
ElementAccessExpression = 182,
|
||||
CallExpression = 183,
|
||||
NewExpression = 184,
|
||||
TaggedTemplateExpression = 185,
|
||||
TypeAssertionExpression = 186,
|
||||
ParenthesizedExpression = 187,
|
||||
FunctionExpression = 188,
|
||||
ArrowFunction = 189,
|
||||
DeleteExpression = 190,
|
||||
TypeOfExpression = 191,
|
||||
VoidExpression = 192,
|
||||
AwaitExpression = 193,
|
||||
PrefixUnaryExpression = 194,
|
||||
PostfixUnaryExpression = 195,
|
||||
BinaryExpression = 196,
|
||||
ConditionalExpression = 197,
|
||||
TemplateExpression = 198,
|
||||
YieldExpression = 199,
|
||||
SpreadElement = 200,
|
||||
ClassExpression = 201,
|
||||
OmittedExpression = 202,
|
||||
ExpressionWithTypeArguments = 203,
|
||||
AsExpression = 204,
|
||||
NonNullExpression = 205,
|
||||
MetaProperty = 206,
|
||||
TemplateSpan = 207,
|
||||
SemicolonClassElement = 208,
|
||||
Block = 209,
|
||||
VariableStatement = 210,
|
||||
EmptyStatement = 211,
|
||||
ExpressionStatement = 212,
|
||||
IfStatement = 213,
|
||||
DoStatement = 214,
|
||||
WhileStatement = 215,
|
||||
ForStatement = 216,
|
||||
ForInStatement = 217,
|
||||
ForOfStatement = 218,
|
||||
ContinueStatement = 219,
|
||||
BreakStatement = 220,
|
||||
ReturnStatement = 221,
|
||||
WithStatement = 222,
|
||||
SwitchStatement = 223,
|
||||
LabeledStatement = 224,
|
||||
ThrowStatement = 225,
|
||||
TryStatement = 226,
|
||||
DebuggerStatement = 227,
|
||||
VariableDeclaration = 228,
|
||||
VariableDeclarationList = 229,
|
||||
FunctionDeclaration = 230,
|
||||
ClassDeclaration = 231,
|
||||
InterfaceDeclaration = 232,
|
||||
TypeAliasDeclaration = 233,
|
||||
EnumDeclaration = 234,
|
||||
ModuleDeclaration = 235,
|
||||
ModuleBlock = 236,
|
||||
CaseBlock = 237,
|
||||
NamespaceExportDeclaration = 238,
|
||||
ImportEqualsDeclaration = 239,
|
||||
ImportDeclaration = 240,
|
||||
ImportClause = 241,
|
||||
NamespaceImport = 242,
|
||||
NamedImports = 243,
|
||||
ImportSpecifier = 244,
|
||||
ExportAssignment = 245,
|
||||
ExportDeclaration = 246,
|
||||
NamedExports = 247,
|
||||
ExportSpecifier = 248,
|
||||
MissingDeclaration = 249,
|
||||
ExternalModuleReference = 250,
|
||||
JsxElement = 251,
|
||||
JsxSelfClosingElement = 252,
|
||||
JsxOpeningElement = 253,
|
||||
JsxClosingElement = 254,
|
||||
JsxFragment = 255,
|
||||
JsxOpeningFragment = 256,
|
||||
JsxClosingFragment = 257,
|
||||
JsxAttribute = 258,
|
||||
JsxAttributes = 259,
|
||||
JsxSpreadAttribute = 260,
|
||||
JsxExpression = 261,
|
||||
CaseClause = 262,
|
||||
DefaultClause = 263,
|
||||
HeritageClause = 264,
|
||||
CatchClause = 265,
|
||||
PropertyAssignment = 266,
|
||||
ShorthandPropertyAssignment = 267,
|
||||
SpreadAssignment = 268,
|
||||
EnumMember = 269,
|
||||
SourceFile = 270,
|
||||
Bundle = 271,
|
||||
JSDocTypeExpression = 272,
|
||||
JSDocAllType = 273,
|
||||
JSDocUnknownType = 274,
|
||||
JSDocNullableType = 275,
|
||||
JSDocNonNullableType = 276,
|
||||
JSDocOptionalType = 277,
|
||||
JSDocFunctionType = 278,
|
||||
JSDocVariadicType = 279,
|
||||
JSDocComment = 280,
|
||||
JSDocTypeLiteral = 281,
|
||||
JSDocTag = 282,
|
||||
JSDocAugmentsTag = 283,
|
||||
JSDocClassTag = 284,
|
||||
JSDocParameterTag = 285,
|
||||
JSDocReturnTag = 286,
|
||||
JSDocTypeTag = 287,
|
||||
JSDocTemplateTag = 288,
|
||||
JSDocTypedefTag = 289,
|
||||
JSDocPropertyTag = 290,
|
||||
SyntaxList = 291,
|
||||
NotEmittedStatement = 292,
|
||||
PartiallyEmittedExpression = 293,
|
||||
CommaListExpression = 294,
|
||||
MergeDeclarationMarker = 295,
|
||||
EndOfDeclarationMarker = 296,
|
||||
Count = 297,
|
||||
FirstAssignment = 58,
|
||||
LastAssignment = 70,
|
||||
FirstCompoundAssignment = 59,
|
||||
@@ -369,7 +370,7 @@ declare namespace ts {
|
||||
FirstFutureReservedWord = 108,
|
||||
LastFutureReservedWord = 116,
|
||||
FirstTypeNode = 159,
|
||||
LastTypeNode = 174,
|
||||
LastTypeNode = 175,
|
||||
FirstPunctuation = 17,
|
||||
LastPunctuation = 70,
|
||||
FirstToken = 0,
|
||||
@@ -383,10 +384,10 @@ declare namespace ts {
|
||||
FirstBinaryOperator = 27,
|
||||
LastBinaryOperator = 70,
|
||||
FirstNode = 144,
|
||||
FirstJSDocNode = 271,
|
||||
LastJSDocNode = 289,
|
||||
FirstJSDocTagNode = 281,
|
||||
LastJSDocTagNode = 289,
|
||||
FirstJSDocNode = 272,
|
||||
LastJSDocNode = 290,
|
||||
FirstJSDocTagNode = 282,
|
||||
LastJSDocTagNode = 290,
|
||||
}
|
||||
enum NodeFlags {
|
||||
None = 0,
|
||||
@@ -734,6 +735,13 @@ declare namespace ts {
|
||||
kind: SyntaxKind.IntersectionType;
|
||||
types: NodeArray<TypeNode>;
|
||||
}
|
||||
interface ConditionalTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.ConditionalType;
|
||||
checkType: TypeNode;
|
||||
extendsType: TypeNode;
|
||||
trueType: TypeNode;
|
||||
falseType: TypeNode;
|
||||
}
|
||||
interface ParenthesizedTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.ParenthesizedType;
|
||||
type: TypeNode;
|
||||
@@ -2044,8 +2052,9 @@ declare namespace ts {
|
||||
Intersection = 262144,
|
||||
Index = 524288,
|
||||
IndexedAccess = 1048576,
|
||||
NonPrimitive = 33554432,
|
||||
MarkerType = 134217728,
|
||||
Conditional = 2097152,
|
||||
Substitution = 4194304,
|
||||
NonPrimitive = 134217728,
|
||||
Literal = 224,
|
||||
Unit = 13536,
|
||||
StringOrNumberLiteral = 96,
|
||||
@@ -2057,10 +2066,13 @@ declare namespace ts {
|
||||
ESSymbolLike = 1536,
|
||||
UnionOrIntersection = 393216,
|
||||
StructuredType = 458752,
|
||||
StructuredOrTypeVariable = 2064384,
|
||||
TypeVariable = 1081344,
|
||||
Narrowable = 35620607,
|
||||
NotUnionOrUnit = 33620481,
|
||||
InstantiableNonPrimitive = 7372800,
|
||||
InstantiablePrimitive = 524288,
|
||||
Instantiable = 7897088,
|
||||
StructuredOrInstantiable = 8355840,
|
||||
Narrowable = 142575359,
|
||||
NotUnionOrUnit = 134283777,
|
||||
}
|
||||
type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
|
||||
interface Type {
|
||||
@@ -2099,6 +2111,8 @@ declare namespace ts {
|
||||
ObjectLiteralPatternWithComputedProperties = 512,
|
||||
ContainsSpread = 1024,
|
||||
ReverseMapped = 2048,
|
||||
JsxAttributes = 4096,
|
||||
MarkerType = 8192,
|
||||
ClassOrInterface = 3,
|
||||
}
|
||||
interface ObjectType extends Type {
|
||||
@@ -2147,17 +2161,27 @@ declare namespace ts {
|
||||
elementType: Type;
|
||||
finalArrayType?: Type;
|
||||
}
|
||||
interface TypeVariable extends Type {
|
||||
interface InstantiableType extends Type {
|
||||
}
|
||||
interface TypeParameter extends TypeVariable {
|
||||
interface TypeParameter extends InstantiableType {
|
||||
}
|
||||
interface IndexedAccessType extends TypeVariable {
|
||||
interface IndexedAccessType extends InstantiableType {
|
||||
objectType: Type;
|
||||
indexType: Type;
|
||||
constraint?: Type;
|
||||
}
|
||||
interface IndexType extends Type {
|
||||
type: TypeVariable | UnionOrIntersectionType;
|
||||
interface IndexType extends InstantiableType {
|
||||
type: InstantiableType | UnionOrIntersectionType;
|
||||
}
|
||||
interface ConditionalType extends InstantiableType {
|
||||
checkType: Type;
|
||||
extendsType: Type;
|
||||
trueType: Type;
|
||||
falseType: Type;
|
||||
}
|
||||
interface SubstitutionType extends InstantiableType {
|
||||
typeParameter: TypeParameter;
|
||||
substitute: Type;
|
||||
}
|
||||
enum SignatureKind {
|
||||
Call = 0,
|
||||
@@ -3048,6 +3072,7 @@ declare namespace ts {
|
||||
function isTupleTypeNode(node: Node): node is TupleTypeNode;
|
||||
function isUnionTypeNode(node: Node): node is UnionTypeNode;
|
||||
function isIntersectionTypeNode(node: Node): node is IntersectionTypeNode;
|
||||
function isConditionalTypeNode(node: Node): node is ConditionalTypeNode;
|
||||
function isParenthesizedTypeNode(node: Node): node is ParenthesizedTypeNode;
|
||||
function isThisTypeNode(node: Node): node is ThisTypeNode;
|
||||
function isTypeOperatorNode(node: Node): node is TypeOperatorNode;
|
||||
@@ -3467,6 +3492,8 @@ declare namespace ts {
|
||||
function createIntersectionTypeNode(types: TypeNode[]): IntersectionTypeNode;
|
||||
function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray<TypeNode>): IntersectionTypeNode;
|
||||
function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: ReadonlyArray<TypeNode>): UnionOrIntersectionTypeNode;
|
||||
function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode;
|
||||
function updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode;
|
||||
function createParenthesizedType(type: TypeNode): ParenthesizedTypeNode;
|
||||
function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode;
|
||||
function createThisTypeNode(): ThisTypeNode;
|
||||
|
||||
+170
-143
@@ -230,134 +230,135 @@ declare namespace ts {
|
||||
TupleType = 166,
|
||||
UnionType = 167,
|
||||
IntersectionType = 168,
|
||||
ParenthesizedType = 169,
|
||||
ThisType = 170,
|
||||
TypeOperator = 171,
|
||||
IndexedAccessType = 172,
|
||||
MappedType = 173,
|
||||
LiteralType = 174,
|
||||
ObjectBindingPattern = 175,
|
||||
ArrayBindingPattern = 176,
|
||||
BindingElement = 177,
|
||||
ArrayLiteralExpression = 178,
|
||||
ObjectLiteralExpression = 179,
|
||||
PropertyAccessExpression = 180,
|
||||
ElementAccessExpression = 181,
|
||||
CallExpression = 182,
|
||||
NewExpression = 183,
|
||||
TaggedTemplateExpression = 184,
|
||||
TypeAssertionExpression = 185,
|
||||
ParenthesizedExpression = 186,
|
||||
FunctionExpression = 187,
|
||||
ArrowFunction = 188,
|
||||
DeleteExpression = 189,
|
||||
TypeOfExpression = 190,
|
||||
VoidExpression = 191,
|
||||
AwaitExpression = 192,
|
||||
PrefixUnaryExpression = 193,
|
||||
PostfixUnaryExpression = 194,
|
||||
BinaryExpression = 195,
|
||||
ConditionalExpression = 196,
|
||||
TemplateExpression = 197,
|
||||
YieldExpression = 198,
|
||||
SpreadElement = 199,
|
||||
ClassExpression = 200,
|
||||
OmittedExpression = 201,
|
||||
ExpressionWithTypeArguments = 202,
|
||||
AsExpression = 203,
|
||||
NonNullExpression = 204,
|
||||
MetaProperty = 205,
|
||||
TemplateSpan = 206,
|
||||
SemicolonClassElement = 207,
|
||||
Block = 208,
|
||||
VariableStatement = 209,
|
||||
EmptyStatement = 210,
|
||||
ExpressionStatement = 211,
|
||||
IfStatement = 212,
|
||||
DoStatement = 213,
|
||||
WhileStatement = 214,
|
||||
ForStatement = 215,
|
||||
ForInStatement = 216,
|
||||
ForOfStatement = 217,
|
||||
ContinueStatement = 218,
|
||||
BreakStatement = 219,
|
||||
ReturnStatement = 220,
|
||||
WithStatement = 221,
|
||||
SwitchStatement = 222,
|
||||
LabeledStatement = 223,
|
||||
ThrowStatement = 224,
|
||||
TryStatement = 225,
|
||||
DebuggerStatement = 226,
|
||||
VariableDeclaration = 227,
|
||||
VariableDeclarationList = 228,
|
||||
FunctionDeclaration = 229,
|
||||
ClassDeclaration = 230,
|
||||
InterfaceDeclaration = 231,
|
||||
TypeAliasDeclaration = 232,
|
||||
EnumDeclaration = 233,
|
||||
ModuleDeclaration = 234,
|
||||
ModuleBlock = 235,
|
||||
CaseBlock = 236,
|
||||
NamespaceExportDeclaration = 237,
|
||||
ImportEqualsDeclaration = 238,
|
||||
ImportDeclaration = 239,
|
||||
ImportClause = 240,
|
||||
NamespaceImport = 241,
|
||||
NamedImports = 242,
|
||||
ImportSpecifier = 243,
|
||||
ExportAssignment = 244,
|
||||
ExportDeclaration = 245,
|
||||
NamedExports = 246,
|
||||
ExportSpecifier = 247,
|
||||
MissingDeclaration = 248,
|
||||
ExternalModuleReference = 249,
|
||||
JsxElement = 250,
|
||||
JsxSelfClosingElement = 251,
|
||||
JsxOpeningElement = 252,
|
||||
JsxClosingElement = 253,
|
||||
JsxFragment = 254,
|
||||
JsxOpeningFragment = 255,
|
||||
JsxClosingFragment = 256,
|
||||
JsxAttribute = 257,
|
||||
JsxAttributes = 258,
|
||||
JsxSpreadAttribute = 259,
|
||||
JsxExpression = 260,
|
||||
CaseClause = 261,
|
||||
DefaultClause = 262,
|
||||
HeritageClause = 263,
|
||||
CatchClause = 264,
|
||||
PropertyAssignment = 265,
|
||||
ShorthandPropertyAssignment = 266,
|
||||
SpreadAssignment = 267,
|
||||
EnumMember = 268,
|
||||
SourceFile = 269,
|
||||
Bundle = 270,
|
||||
JSDocTypeExpression = 271,
|
||||
JSDocAllType = 272,
|
||||
JSDocUnknownType = 273,
|
||||
JSDocNullableType = 274,
|
||||
JSDocNonNullableType = 275,
|
||||
JSDocOptionalType = 276,
|
||||
JSDocFunctionType = 277,
|
||||
JSDocVariadicType = 278,
|
||||
JSDocComment = 279,
|
||||
JSDocTypeLiteral = 280,
|
||||
JSDocTag = 281,
|
||||
JSDocAugmentsTag = 282,
|
||||
JSDocClassTag = 283,
|
||||
JSDocParameterTag = 284,
|
||||
JSDocReturnTag = 285,
|
||||
JSDocTypeTag = 286,
|
||||
JSDocTemplateTag = 287,
|
||||
JSDocTypedefTag = 288,
|
||||
JSDocPropertyTag = 289,
|
||||
SyntaxList = 290,
|
||||
NotEmittedStatement = 291,
|
||||
PartiallyEmittedExpression = 292,
|
||||
CommaListExpression = 293,
|
||||
MergeDeclarationMarker = 294,
|
||||
EndOfDeclarationMarker = 295,
|
||||
Count = 296,
|
||||
ConditionalType = 169,
|
||||
ParenthesizedType = 170,
|
||||
ThisType = 171,
|
||||
TypeOperator = 172,
|
||||
IndexedAccessType = 173,
|
||||
MappedType = 174,
|
||||
LiteralType = 175,
|
||||
ObjectBindingPattern = 176,
|
||||
ArrayBindingPattern = 177,
|
||||
BindingElement = 178,
|
||||
ArrayLiteralExpression = 179,
|
||||
ObjectLiteralExpression = 180,
|
||||
PropertyAccessExpression = 181,
|
||||
ElementAccessExpression = 182,
|
||||
CallExpression = 183,
|
||||
NewExpression = 184,
|
||||
TaggedTemplateExpression = 185,
|
||||
TypeAssertionExpression = 186,
|
||||
ParenthesizedExpression = 187,
|
||||
FunctionExpression = 188,
|
||||
ArrowFunction = 189,
|
||||
DeleteExpression = 190,
|
||||
TypeOfExpression = 191,
|
||||
VoidExpression = 192,
|
||||
AwaitExpression = 193,
|
||||
PrefixUnaryExpression = 194,
|
||||
PostfixUnaryExpression = 195,
|
||||
BinaryExpression = 196,
|
||||
ConditionalExpression = 197,
|
||||
TemplateExpression = 198,
|
||||
YieldExpression = 199,
|
||||
SpreadElement = 200,
|
||||
ClassExpression = 201,
|
||||
OmittedExpression = 202,
|
||||
ExpressionWithTypeArguments = 203,
|
||||
AsExpression = 204,
|
||||
NonNullExpression = 205,
|
||||
MetaProperty = 206,
|
||||
TemplateSpan = 207,
|
||||
SemicolonClassElement = 208,
|
||||
Block = 209,
|
||||
VariableStatement = 210,
|
||||
EmptyStatement = 211,
|
||||
ExpressionStatement = 212,
|
||||
IfStatement = 213,
|
||||
DoStatement = 214,
|
||||
WhileStatement = 215,
|
||||
ForStatement = 216,
|
||||
ForInStatement = 217,
|
||||
ForOfStatement = 218,
|
||||
ContinueStatement = 219,
|
||||
BreakStatement = 220,
|
||||
ReturnStatement = 221,
|
||||
WithStatement = 222,
|
||||
SwitchStatement = 223,
|
||||
LabeledStatement = 224,
|
||||
ThrowStatement = 225,
|
||||
TryStatement = 226,
|
||||
DebuggerStatement = 227,
|
||||
VariableDeclaration = 228,
|
||||
VariableDeclarationList = 229,
|
||||
FunctionDeclaration = 230,
|
||||
ClassDeclaration = 231,
|
||||
InterfaceDeclaration = 232,
|
||||
TypeAliasDeclaration = 233,
|
||||
EnumDeclaration = 234,
|
||||
ModuleDeclaration = 235,
|
||||
ModuleBlock = 236,
|
||||
CaseBlock = 237,
|
||||
NamespaceExportDeclaration = 238,
|
||||
ImportEqualsDeclaration = 239,
|
||||
ImportDeclaration = 240,
|
||||
ImportClause = 241,
|
||||
NamespaceImport = 242,
|
||||
NamedImports = 243,
|
||||
ImportSpecifier = 244,
|
||||
ExportAssignment = 245,
|
||||
ExportDeclaration = 246,
|
||||
NamedExports = 247,
|
||||
ExportSpecifier = 248,
|
||||
MissingDeclaration = 249,
|
||||
ExternalModuleReference = 250,
|
||||
JsxElement = 251,
|
||||
JsxSelfClosingElement = 252,
|
||||
JsxOpeningElement = 253,
|
||||
JsxClosingElement = 254,
|
||||
JsxFragment = 255,
|
||||
JsxOpeningFragment = 256,
|
||||
JsxClosingFragment = 257,
|
||||
JsxAttribute = 258,
|
||||
JsxAttributes = 259,
|
||||
JsxSpreadAttribute = 260,
|
||||
JsxExpression = 261,
|
||||
CaseClause = 262,
|
||||
DefaultClause = 263,
|
||||
HeritageClause = 264,
|
||||
CatchClause = 265,
|
||||
PropertyAssignment = 266,
|
||||
ShorthandPropertyAssignment = 267,
|
||||
SpreadAssignment = 268,
|
||||
EnumMember = 269,
|
||||
SourceFile = 270,
|
||||
Bundle = 271,
|
||||
JSDocTypeExpression = 272,
|
||||
JSDocAllType = 273,
|
||||
JSDocUnknownType = 274,
|
||||
JSDocNullableType = 275,
|
||||
JSDocNonNullableType = 276,
|
||||
JSDocOptionalType = 277,
|
||||
JSDocFunctionType = 278,
|
||||
JSDocVariadicType = 279,
|
||||
JSDocComment = 280,
|
||||
JSDocTypeLiteral = 281,
|
||||
JSDocTag = 282,
|
||||
JSDocAugmentsTag = 283,
|
||||
JSDocClassTag = 284,
|
||||
JSDocParameterTag = 285,
|
||||
JSDocReturnTag = 286,
|
||||
JSDocTypeTag = 287,
|
||||
JSDocTemplateTag = 288,
|
||||
JSDocTypedefTag = 289,
|
||||
JSDocPropertyTag = 290,
|
||||
SyntaxList = 291,
|
||||
NotEmittedStatement = 292,
|
||||
PartiallyEmittedExpression = 293,
|
||||
CommaListExpression = 294,
|
||||
MergeDeclarationMarker = 295,
|
||||
EndOfDeclarationMarker = 296,
|
||||
Count = 297,
|
||||
FirstAssignment = 58,
|
||||
LastAssignment = 70,
|
||||
FirstCompoundAssignment = 59,
|
||||
@@ -369,7 +370,7 @@ declare namespace ts {
|
||||
FirstFutureReservedWord = 108,
|
||||
LastFutureReservedWord = 116,
|
||||
FirstTypeNode = 159,
|
||||
LastTypeNode = 174,
|
||||
LastTypeNode = 175,
|
||||
FirstPunctuation = 17,
|
||||
LastPunctuation = 70,
|
||||
FirstToken = 0,
|
||||
@@ -383,10 +384,10 @@ declare namespace ts {
|
||||
FirstBinaryOperator = 27,
|
||||
LastBinaryOperator = 70,
|
||||
FirstNode = 144,
|
||||
FirstJSDocNode = 271,
|
||||
LastJSDocNode = 289,
|
||||
FirstJSDocTagNode = 281,
|
||||
LastJSDocTagNode = 289,
|
||||
FirstJSDocNode = 272,
|
||||
LastJSDocNode = 290,
|
||||
FirstJSDocTagNode = 282,
|
||||
LastJSDocTagNode = 290,
|
||||
}
|
||||
enum NodeFlags {
|
||||
None = 0,
|
||||
@@ -734,6 +735,13 @@ declare namespace ts {
|
||||
kind: SyntaxKind.IntersectionType;
|
||||
types: NodeArray<TypeNode>;
|
||||
}
|
||||
interface ConditionalTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.ConditionalType;
|
||||
checkType: TypeNode;
|
||||
extendsType: TypeNode;
|
||||
trueType: TypeNode;
|
||||
falseType: TypeNode;
|
||||
}
|
||||
interface ParenthesizedTypeNode extends TypeNode {
|
||||
kind: SyntaxKind.ParenthesizedType;
|
||||
type: TypeNode;
|
||||
@@ -2044,8 +2052,9 @@ declare namespace ts {
|
||||
Intersection = 262144,
|
||||
Index = 524288,
|
||||
IndexedAccess = 1048576,
|
||||
NonPrimitive = 33554432,
|
||||
MarkerType = 134217728,
|
||||
Conditional = 2097152,
|
||||
Substitution = 4194304,
|
||||
NonPrimitive = 134217728,
|
||||
Literal = 224,
|
||||
Unit = 13536,
|
||||
StringOrNumberLiteral = 96,
|
||||
@@ -2057,10 +2066,13 @@ declare namespace ts {
|
||||
ESSymbolLike = 1536,
|
||||
UnionOrIntersection = 393216,
|
||||
StructuredType = 458752,
|
||||
StructuredOrTypeVariable = 2064384,
|
||||
TypeVariable = 1081344,
|
||||
Narrowable = 35620607,
|
||||
NotUnionOrUnit = 33620481,
|
||||
InstantiableNonPrimitive = 7372800,
|
||||
InstantiablePrimitive = 524288,
|
||||
Instantiable = 7897088,
|
||||
StructuredOrInstantiable = 8355840,
|
||||
Narrowable = 142575359,
|
||||
NotUnionOrUnit = 134283777,
|
||||
}
|
||||
type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression;
|
||||
interface Type {
|
||||
@@ -2099,6 +2111,8 @@ declare namespace ts {
|
||||
ObjectLiteralPatternWithComputedProperties = 512,
|
||||
ContainsSpread = 1024,
|
||||
ReverseMapped = 2048,
|
||||
JsxAttributes = 4096,
|
||||
MarkerType = 8192,
|
||||
ClassOrInterface = 3,
|
||||
}
|
||||
interface ObjectType extends Type {
|
||||
@@ -2147,17 +2161,27 @@ declare namespace ts {
|
||||
elementType: Type;
|
||||
finalArrayType?: Type;
|
||||
}
|
||||
interface TypeVariable extends Type {
|
||||
interface InstantiableType extends Type {
|
||||
}
|
||||
interface TypeParameter extends TypeVariable {
|
||||
interface TypeParameter extends InstantiableType {
|
||||
}
|
||||
interface IndexedAccessType extends TypeVariable {
|
||||
interface IndexedAccessType extends InstantiableType {
|
||||
objectType: Type;
|
||||
indexType: Type;
|
||||
constraint?: Type;
|
||||
}
|
||||
interface IndexType extends Type {
|
||||
type: TypeVariable | UnionOrIntersectionType;
|
||||
interface IndexType extends InstantiableType {
|
||||
type: InstantiableType | UnionOrIntersectionType;
|
||||
}
|
||||
interface ConditionalType extends InstantiableType {
|
||||
checkType: Type;
|
||||
extendsType: Type;
|
||||
trueType: Type;
|
||||
falseType: Type;
|
||||
}
|
||||
interface SubstitutionType extends InstantiableType {
|
||||
typeParameter: TypeParameter;
|
||||
substitute: Type;
|
||||
}
|
||||
enum SignatureKind {
|
||||
Call = 0,
|
||||
@@ -3103,6 +3127,7 @@ declare namespace ts {
|
||||
function isTupleTypeNode(node: Node): node is TupleTypeNode;
|
||||
function isUnionTypeNode(node: Node): node is UnionTypeNode;
|
||||
function isIntersectionTypeNode(node: Node): node is IntersectionTypeNode;
|
||||
function isConditionalTypeNode(node: Node): node is ConditionalTypeNode;
|
||||
function isParenthesizedTypeNode(node: Node): node is ParenthesizedTypeNode;
|
||||
function isThisTypeNode(node: Node): node is ThisTypeNode;
|
||||
function isTypeOperatorNode(node: Node): node is TypeOperatorNode;
|
||||
@@ -3414,6 +3439,8 @@ declare namespace ts {
|
||||
function createIntersectionTypeNode(types: TypeNode[]): IntersectionTypeNode;
|
||||
function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray<TypeNode>): IntersectionTypeNode;
|
||||
function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: ReadonlyArray<TypeNode>): UnionOrIntersectionTypeNode;
|
||||
function createConditionalTypeNode(checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode;
|
||||
function updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode;
|
||||
function createParenthesizedType(type: TypeNode): ParenthesizedTypeNode;
|
||||
function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode;
|
||||
function createThisTypeNode(): ThisTypeNode;
|
||||
|
||||
@@ -0,0 +1,337 @@
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(16,5): error TS2322: Type 'T' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(21,5): error TS2322: Type 'T' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
Type 'string | undefined' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
Type 'undefined' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(22,9): error TS2322: Type 'T' is not assignable to type 'string'.
|
||||
Type 'string | undefined' is not assignable to type 'string'.
|
||||
Type 'undefined' is not assignable to type 'string'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(28,5): error TS2322: Type 'Partial<T>[keyof T]' is not assignable to type 'Diff<Partial<T>[keyof T], null | undefined>'.
|
||||
Type 'T[keyof T] | undefined' is not assignable to type 'Diff<Partial<T>[keyof T], null | undefined>'.
|
||||
Type 'undefined' is not assignable to type 'Diff<Partial<T>[keyof T], null | undefined>'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(100,5): error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(101,5): error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>'.
|
||||
Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(105,5): error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>'.
|
||||
Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(111,5): error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(112,5): error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(113,5): error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(114,5): error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(131,10): error TS2540: Cannot assign to 'id' because it is a constant or a read-only property.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(132,5): error TS2542: Index signature in type 'DeepReadonlyArray<Part>' only permits reading.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(133,22): error TS2540: Cannot assign to 'id' because it is a constant or a read-only property.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(134,10): error TS2339: Property 'updatePart' does not exist on type 'DeepReadonlyObject<Part>'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(156,5): error TS2322: Type 'ZeroOf<T>' is not assignable to type 'T'.
|
||||
Type '0 | (T extends string ? "" : false)' is not assignable to type 'T'.
|
||||
Type '0' is not assignable to type 'T'.
|
||||
Type '"" | 0' is not assignable to type 'T'.
|
||||
Type '""' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes1.ts(157,5): error TS2322: Type 'T' is not assignable to type 'ZeroOf<T>'.
|
||||
Type 'string | number' is not assignable to type 'ZeroOf<T>'.
|
||||
Type 'string' is not assignable to type 'ZeroOf<T>'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/conditional/conditionalTypes1.ts (18 errors) ====
|
||||
type Diff<T, U> = T extends U ? never : T;
|
||||
type Filter<T, U> = T extends U ? T : never;
|
||||
type NonNullable<T> = Diff<T, null | undefined>;
|
||||
|
||||
type T00 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
|
||||
type T01 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
|
||||
|
||||
type T02 = Diff<string | number | (() => void), Function>; // string | number
|
||||
type T03 = Filter<string | number | (() => void), Function>; // () => void
|
||||
|
||||
type T04 = NonNullable<string | number | undefined>; // string | number
|
||||
type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
|
||||
|
||||
function f1<T>(x: T, y: NonNullable<T>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
}
|
||||
|
||||
function f2<T extends string | undefined>(x: T, y: NonNullable<T>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
!!! error TS2322: Type 'string | undefined' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'Diff<T, null | undefined>'.
|
||||
let s1: string = x; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'string'.
|
||||
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
|
||||
let s2: string = y;
|
||||
}
|
||||
|
||||
function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'Partial<T>[keyof T]' is not assignable to type 'Diff<Partial<T>[keyof T], null | undefined>'.
|
||||
!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'Diff<Partial<T>[keyof T], null | undefined>'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'Diff<Partial<T>[keyof T], null | undefined>'.
|
||||
}
|
||||
|
||||
type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean };
|
||||
|
||||
type T10 = Diff<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
|
||||
type T11 = Filter<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T12 = Diff<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
|
||||
type T13 = Filter<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T14 = Diff<Options, { q: "a" }>; // Options
|
||||
type T15 = Filter<Options, { q: "a" }>; // never
|
||||
|
||||
declare function f4<T extends Options, K extends string>(p: K): Filter<T, { k: K }>;
|
||||
let x0 = f4("a"); // { k: "a", a: number }
|
||||
|
||||
type OptionsOfKind<K extends Options["k"]> = Filter<Options, { k: K }>;
|
||||
|
||||
type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type Select<T, K extends keyof T, V extends T[K]> = Filter<T, { [P in K]: V }>;
|
||||
|
||||
type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type TypeName<T> =
|
||||
T extends string ? "string" :
|
||||
T extends number ? "number" :
|
||||
T extends boolean ? "boolean" :
|
||||
T extends undefined ? "undefined" :
|
||||
T extends Function ? "function" :
|
||||
"object";
|
||||
|
||||
type T20 = TypeName<string | (() => void)>; // "string" | "function"
|
||||
type T21 = TypeName<any>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
type T22 = TypeName<never>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
type T23 = TypeName<{}>; // "object"
|
||||
|
||||
type KnockoutObservable<T> = { object: T };
|
||||
type KnockoutObservableArray<T> = { array: T };
|
||||
|
||||
type KnockedOut<T> = T extends any[] ? KnockoutObservableArray<T[number]> : KnockoutObservable<T>;
|
||||
|
||||
type KnockedOutObj<T> = {
|
||||
[P in keyof T]: KnockedOut<T[P]>;
|
||||
}
|
||||
|
||||
interface Item {
|
||||
id: number;
|
||||
name: string;
|
||||
subitems: string[];
|
||||
}
|
||||
|
||||
type KOItem = KnockedOutObj<Item>;
|
||||
|
||||
interface Part {
|
||||
id: number;
|
||||
name: string;
|
||||
subparts: Part[];
|
||||
updatePart(newName: string): void;
|
||||
}
|
||||
|
||||
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
||||
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
||||
|
||||
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
|
||||
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
||||
|
||||
type T30 = FunctionProperties<Part>;
|
||||
type T31 = NonFunctionProperties<Part>;
|
||||
|
||||
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
|
||||
x = y; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>' is not assignable to type 'T'.
|
||||
x = z; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>' is not assignable to type 'T'.
|
||||
y = x;
|
||||
y = z; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>'.
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
z = x;
|
||||
z = y; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>' is not assignable to type 'Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>'.
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
}
|
||||
|
||||
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
y = z; // Error
|
||||
~
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
|
||||
z = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
z = y; // Error
|
||||
~
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
|
||||
}
|
||||
|
||||
type DeepReadonly<T> =
|
||||
T extends any[] ? DeepReadonlyArray<T[number]> :
|
||||
T extends object ? DeepReadonlyObject<T> :
|
||||
T;
|
||||
|
||||
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
|
||||
|
||||
type DeepReadonlyObject<T> = {
|
||||
readonly [P in NonFunctionPropertyNames<T>]: DeepReadonly<T[P]>;
|
||||
};
|
||||
|
||||
function f10(part: DeepReadonly<Part>) {
|
||||
let name: string = part.name;
|
||||
let id: number = part.subparts[0].id;
|
||||
part.id = part.id; // Error
|
||||
~~
|
||||
!!! error TS2540: Cannot assign to 'id' because it is a constant or a read-only property.
|
||||
part.subparts[0] = part.subparts[0]; // Error
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! error TS2542: Index signature in type 'DeepReadonlyArray<Part>' only permits reading.
|
||||
part.subparts[0].id = part.subparts[0].id; // Error
|
||||
~~
|
||||
!!! error TS2540: Cannot assign to 'id' because it is a constant or a read-only property.
|
||||
part.updatePart("hello"); // Error
|
||||
~~~~~~~~~~
|
||||
!!! error TS2339: Property 'updatePart' does not exist on type 'DeepReadonlyObject<Part>'.
|
||||
}
|
||||
|
||||
type ZeroOf<T extends number | string | boolean> = T extends number ? 0 : T extends string ? "" : false;
|
||||
|
||||
function zeroOf<T extends number | string | boolean>(value: T) {
|
||||
return <ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
|
||||
}
|
||||
|
||||
function f20<T extends string>(n: number, b: boolean, x: number | boolean, y: T) {
|
||||
zeroOf(5); // 0
|
||||
zeroOf("hello"); // ""
|
||||
zeroOf(true); // false
|
||||
zeroOf(n); // 0
|
||||
zeroOf(b); // False
|
||||
zeroOf(x); // 0 | false
|
||||
zeroOf(y); // ZeroOf<T>
|
||||
}
|
||||
|
||||
function f21<T extends number | string>(x: T, y: ZeroOf<T>) {
|
||||
let z1: number | string = y;
|
||||
let z2: 0 | "" = y;
|
||||
x = y; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'ZeroOf<T>' is not assignable to type 'T'.
|
||||
!!! error TS2322: Type '0 | (T extends string ? "" : false)' is not assignable to type 'T'.
|
||||
!!! error TS2322: Type '0' is not assignable to type 'T'.
|
||||
!!! error TS2322: Type '"" | 0' is not assignable to type 'T'.
|
||||
!!! error TS2322: Type '""' is not assignable to type 'T'.
|
||||
y = x; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'ZeroOf<T>'.
|
||||
!!! error TS2322: Type 'string | number' is not assignable to type 'ZeroOf<T>'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'ZeroOf<T>'.
|
||||
}
|
||||
|
||||
type Extends<T, U> = T extends U ? true : false;
|
||||
type If<C extends boolean, T, F> = C extends true ? T : F;
|
||||
type Not<C extends boolean> = If<C, false, true>;
|
||||
type And<A extends boolean, B extends boolean> = If<A, B, false>;
|
||||
type Or<A extends boolean, B extends boolean> = If<A, true, B>;
|
||||
|
||||
type isString<T> = Extends<T, string>;
|
||||
|
||||
type Q1 = isString<number>; // false
|
||||
type Q2 = isString<"abc">; // true
|
||||
type Q3 = isString<any>; // boolean
|
||||
type Q4 = isString<never>; // boolean
|
||||
|
||||
type N1 = Not<false>; // true
|
||||
type N2 = Not<true>; // false
|
||||
type N3 = Not<boolean>; // boolean
|
||||
|
||||
type A1 = And<false, false>; // false
|
||||
type A2 = And<false, true>; // false
|
||||
type A3 = And<true, false>; // false
|
||||
type A4 = And<true, true>; // true
|
||||
type A5 = And<boolean, false>; // false
|
||||
type A6 = And<false, boolean>; // false
|
||||
type A7 = And<boolean, true>; // boolean
|
||||
type A8 = And<true, boolean>; // boolean
|
||||
type A9 = And<boolean, boolean>; // boolean
|
||||
|
||||
type O1 = Or<false, false>; // false
|
||||
type O2 = Or<false, true>; // true
|
||||
type O3 = Or<true, false>; // true
|
||||
type O4 = Or<true, true>; // true
|
||||
type O5 = Or<boolean, false>; // boolean
|
||||
type O6 = Or<false, boolean>; // boolean
|
||||
type O7 = Or<boolean, true>; // true
|
||||
type O8 = Or<true, boolean>; // true
|
||||
type O9 = Or<boolean, boolean>; // boolean
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
//// [conditionalTypes1.ts]
|
||||
type Diff<T, U> = T extends U ? never : T;
|
||||
type Filter<T, U> = T extends U ? T : never;
|
||||
type NonNullable<T> = Diff<T, null | undefined>;
|
||||
|
||||
type T00 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
|
||||
type T01 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
|
||||
|
||||
type T02 = Diff<string | number | (() => void), Function>; // string | number
|
||||
type T03 = Filter<string | number | (() => void), Function>; // () => void
|
||||
|
||||
type T04 = NonNullable<string | number | undefined>; // string | number
|
||||
type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
|
||||
|
||||
function f1<T>(x: T, y: NonNullable<T>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
function f2<T extends string | undefined>(x: T, y: NonNullable<T>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
let s1: string = x; // Error
|
||||
let s2: string = y;
|
||||
}
|
||||
|
||||
function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean };
|
||||
|
||||
type T10 = Diff<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
|
||||
type T11 = Filter<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T12 = Diff<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
|
||||
type T13 = Filter<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T14 = Diff<Options, { q: "a" }>; // Options
|
||||
type T15 = Filter<Options, { q: "a" }>; // never
|
||||
|
||||
declare function f4<T extends Options, K extends string>(p: K): Filter<T, { k: K }>;
|
||||
let x0 = f4("a"); // { k: "a", a: number }
|
||||
|
||||
type OptionsOfKind<K extends Options["k"]> = Filter<Options, { k: K }>;
|
||||
|
||||
type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type Select<T, K extends keyof T, V extends T[K]> = Filter<T, { [P in K]: V }>;
|
||||
|
||||
type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type TypeName<T> =
|
||||
T extends string ? "string" :
|
||||
T extends number ? "number" :
|
||||
T extends boolean ? "boolean" :
|
||||
T extends undefined ? "undefined" :
|
||||
T extends Function ? "function" :
|
||||
"object";
|
||||
|
||||
type T20 = TypeName<string | (() => void)>; // "string" | "function"
|
||||
type T21 = TypeName<any>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
type T22 = TypeName<never>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
type T23 = TypeName<{}>; // "object"
|
||||
|
||||
type KnockoutObservable<T> = { object: T };
|
||||
type KnockoutObservableArray<T> = { array: T };
|
||||
|
||||
type KnockedOut<T> = T extends any[] ? KnockoutObservableArray<T[number]> : KnockoutObservable<T>;
|
||||
|
||||
type KnockedOutObj<T> = {
|
||||
[P in keyof T]: KnockedOut<T[P]>;
|
||||
}
|
||||
|
||||
interface Item {
|
||||
id: number;
|
||||
name: string;
|
||||
subitems: string[];
|
||||
}
|
||||
|
||||
type KOItem = KnockedOutObj<Item>;
|
||||
|
||||
interface Part {
|
||||
id: number;
|
||||
name: string;
|
||||
subparts: Part[];
|
||||
updatePart(newName: string): void;
|
||||
}
|
||||
|
||||
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
||||
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
||||
|
||||
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
|
||||
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
||||
|
||||
type T30 = FunctionProperties<Part>;
|
||||
type T31 = NonFunctionProperties<Part>;
|
||||
|
||||
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
|
||||
x = y; // Error
|
||||
x = z; // Error
|
||||
y = x;
|
||||
y = z; // Error
|
||||
z = x;
|
||||
z = y; // Error
|
||||
}
|
||||
|
||||
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
y = z; // Error
|
||||
z = x; // Error
|
||||
z = y; // Error
|
||||
}
|
||||
|
||||
type DeepReadonly<T> =
|
||||
T extends any[] ? DeepReadonlyArray<T[number]> :
|
||||
T extends object ? DeepReadonlyObject<T> :
|
||||
T;
|
||||
|
||||
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
|
||||
|
||||
type DeepReadonlyObject<T> = {
|
||||
readonly [P in NonFunctionPropertyNames<T>]: DeepReadonly<T[P]>;
|
||||
};
|
||||
|
||||
function f10(part: DeepReadonly<Part>) {
|
||||
let name: string = part.name;
|
||||
let id: number = part.subparts[0].id;
|
||||
part.id = part.id; // Error
|
||||
part.subparts[0] = part.subparts[0]; // Error
|
||||
part.subparts[0].id = part.subparts[0].id; // Error
|
||||
part.updatePart("hello"); // Error
|
||||
}
|
||||
|
||||
type ZeroOf<T extends number | string | boolean> = T extends number ? 0 : T extends string ? "" : false;
|
||||
|
||||
function zeroOf<T extends number | string | boolean>(value: T) {
|
||||
return <ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
|
||||
}
|
||||
|
||||
function f20<T extends string>(n: number, b: boolean, x: number | boolean, y: T) {
|
||||
zeroOf(5); // 0
|
||||
zeroOf("hello"); // ""
|
||||
zeroOf(true); // false
|
||||
zeroOf(n); // 0
|
||||
zeroOf(b); // False
|
||||
zeroOf(x); // 0 | false
|
||||
zeroOf(y); // ZeroOf<T>
|
||||
}
|
||||
|
||||
function f21<T extends number | string>(x: T, y: ZeroOf<T>) {
|
||||
let z1: number | string = y;
|
||||
let z2: 0 | "" = y;
|
||||
x = y; // Error
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
type Extends<T, U> = T extends U ? true : false;
|
||||
type If<C extends boolean, T, F> = C extends true ? T : F;
|
||||
type Not<C extends boolean> = If<C, false, true>;
|
||||
type And<A extends boolean, B extends boolean> = If<A, B, false>;
|
||||
type Or<A extends boolean, B extends boolean> = If<A, true, B>;
|
||||
|
||||
type isString<T> = Extends<T, string>;
|
||||
|
||||
type Q1 = isString<number>; // false
|
||||
type Q2 = isString<"abc">; // true
|
||||
type Q3 = isString<any>; // boolean
|
||||
type Q4 = isString<never>; // boolean
|
||||
|
||||
type N1 = Not<false>; // true
|
||||
type N2 = Not<true>; // false
|
||||
type N3 = Not<boolean>; // boolean
|
||||
|
||||
type A1 = And<false, false>; // false
|
||||
type A2 = And<false, true>; // false
|
||||
type A3 = And<true, false>; // false
|
||||
type A4 = And<true, true>; // true
|
||||
type A5 = And<boolean, false>; // false
|
||||
type A6 = And<false, boolean>; // false
|
||||
type A7 = And<boolean, true>; // boolean
|
||||
type A8 = And<true, boolean>; // boolean
|
||||
type A9 = And<boolean, boolean>; // boolean
|
||||
|
||||
type O1 = Or<false, false>; // false
|
||||
type O2 = Or<false, true>; // true
|
||||
type O3 = Or<true, false>; // true
|
||||
type O4 = Or<true, true>; // true
|
||||
type O5 = Or<boolean, false>; // boolean
|
||||
type O6 = Or<false, boolean>; // boolean
|
||||
type O7 = Or<boolean, true>; // true
|
||||
type O8 = Or<true, boolean>; // true
|
||||
type O9 = Or<boolean, boolean>; // boolean
|
||||
|
||||
|
||||
//// [conditionalTypes1.js]
|
||||
"use strict";
|
||||
function f1(x, y) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
function f2(x, y) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
var s1 = x; // Error
|
||||
var s2 = y;
|
||||
}
|
||||
function f3(x, y) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
var x0 = f4("a"); // { k: "a", a: number }
|
||||
function f7(x, y, z) {
|
||||
x = y; // Error
|
||||
x = z; // Error
|
||||
y = x;
|
||||
y = z; // Error
|
||||
z = x;
|
||||
z = y; // Error
|
||||
}
|
||||
function f8(x, y, z) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
y = z; // Error
|
||||
z = x; // Error
|
||||
z = y; // Error
|
||||
}
|
||||
function f10(part) {
|
||||
var name = part.name;
|
||||
var id = part.subparts[0].id;
|
||||
part.id = part.id; // Error
|
||||
part.subparts[0] = part.subparts[0]; // Error
|
||||
part.subparts[0].id = part.subparts[0].id; // Error
|
||||
part.updatePart("hello"); // Error
|
||||
}
|
||||
function zeroOf(value) {
|
||||
return (typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
|
||||
}
|
||||
function f20(n, b, x, y) {
|
||||
zeroOf(5); // 0
|
||||
zeroOf("hello"); // ""
|
||||
zeroOf(true); // false
|
||||
zeroOf(n); // 0
|
||||
zeroOf(b); // False
|
||||
zeroOf(x); // 0 | false
|
||||
zeroOf(y); // ZeroOf<T>
|
||||
}
|
||||
function f21(x, y) {
|
||||
var z1 = y;
|
||||
var z2 = y;
|
||||
x = y; // Error
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
|
||||
//// [conditionalTypes1.d.ts]
|
||||
declare type Diff<T, U> = T extends U ? never : T;
|
||||
declare type Filter<T, U> = T extends U ? T : never;
|
||||
declare type NonNullable<T> = Diff<T, null | undefined>;
|
||||
declare type T00 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">;
|
||||
declare type T01 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">;
|
||||
declare type T02 = Diff<string | number | (() => void), Function>;
|
||||
declare type T03 = Filter<string | number | (() => void), Function>;
|
||||
declare type T04 = NonNullable<string | number | undefined>;
|
||||
declare type T05 = NonNullable<(() => string) | string[] | null | undefined>;
|
||||
declare function f1<T>(x: T, y: NonNullable<T>): void;
|
||||
declare function f2<T extends string | undefined>(x: T, y: NonNullable<T>): void;
|
||||
declare function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>): void;
|
||||
declare type Options = {
|
||||
k: "a";
|
||||
a: number;
|
||||
} | {
|
||||
k: "b";
|
||||
b: string;
|
||||
} | {
|
||||
k: "c";
|
||||
c: boolean;
|
||||
};
|
||||
declare type T10 = Diff<Options, {
|
||||
k: "a" | "b";
|
||||
}>;
|
||||
declare type T11 = Filter<Options, {
|
||||
k: "a" | "b";
|
||||
}>;
|
||||
declare type T12 = Diff<Options, {
|
||||
k: "a";
|
||||
} | {
|
||||
k: "b";
|
||||
}>;
|
||||
declare type T13 = Filter<Options, {
|
||||
k: "a";
|
||||
} | {
|
||||
k: "b";
|
||||
}>;
|
||||
declare type T14 = Diff<Options, {
|
||||
q: "a";
|
||||
}>;
|
||||
declare type T15 = Filter<Options, {
|
||||
q: "a";
|
||||
}>;
|
||||
declare function f4<T extends Options, K extends string>(p: K): Filter<T, {
|
||||
k: K;
|
||||
}>;
|
||||
declare let x0: {
|
||||
k: "a";
|
||||
a: number;
|
||||
};
|
||||
declare type OptionsOfKind<K extends Options["k"]> = Filter<Options, {
|
||||
k: K;
|
||||
}>;
|
||||
declare type T16 = OptionsOfKind<"a" | "b">;
|
||||
declare type Select<T, K extends keyof T, V extends T[K]> = Filter<T, {
|
||||
[P in K]: V;
|
||||
}>;
|
||||
declare type T17 = Select<Options, "k", "a" | "b">;
|
||||
declare type TypeName<T> = T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T extends undefined ? "undefined" : T extends Function ? "function" : "object";
|
||||
declare type T20 = TypeName<string | (() => void)>;
|
||||
declare type T21 = TypeName<any>;
|
||||
declare type T22 = TypeName<never>;
|
||||
declare type T23 = TypeName<{}>;
|
||||
declare type KnockoutObservable<T> = {
|
||||
object: T;
|
||||
};
|
||||
declare type KnockoutObservableArray<T> = {
|
||||
array: T;
|
||||
};
|
||||
declare type KnockedOut<T> = T extends any[] ? KnockoutObservableArray<T[number]> : KnockoutObservable<T>;
|
||||
declare type KnockedOutObj<T> = {
|
||||
[P in keyof T]: KnockedOut<T[P]>;
|
||||
};
|
||||
interface Item {
|
||||
id: number;
|
||||
name: string;
|
||||
subitems: string[];
|
||||
}
|
||||
declare type KOItem = KnockedOutObj<Item>;
|
||||
interface Part {
|
||||
id: number;
|
||||
name: string;
|
||||
subparts: Part[];
|
||||
updatePart(newName: string): void;
|
||||
}
|
||||
declare type FunctionPropertyNames<T> = {
|
||||
[K in keyof T]: T[K] extends Function ? K : never;
|
||||
}[keyof T];
|
||||
declare type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
||||
declare type NonFunctionPropertyNames<T> = {
|
||||
[K in keyof T]: T[K] extends Function ? never : K;
|
||||
}[keyof T];
|
||||
declare type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
||||
declare type T30 = FunctionProperties<Part>;
|
||||
declare type T31 = NonFunctionProperties<Part>;
|
||||
declare function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>): void;
|
||||
declare function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>): void;
|
||||
declare type DeepReadonly<T> = T extends any[] ? DeepReadonlyArray<T[number]> : T extends object ? DeepReadonlyObject<T> : T;
|
||||
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {
|
||||
}
|
||||
declare type DeepReadonlyObject<T> = {
|
||||
readonly [P in NonFunctionPropertyNames<T>]: DeepReadonly<T[P]>;
|
||||
};
|
||||
declare function f10(part: DeepReadonly<Part>): void;
|
||||
declare type ZeroOf<T extends number | string | boolean> = T extends number ? 0 : T extends string ? "" : false;
|
||||
declare function zeroOf<T extends number | string | boolean>(value: T): ZeroOf<T>;
|
||||
declare function f20<T extends string>(n: number, b: boolean, x: number | boolean, y: T): void;
|
||||
declare function f21<T extends number | string>(x: T, y: ZeroOf<T>): void;
|
||||
declare type Extends<T, U> = T extends U ? true : false;
|
||||
declare type If<C extends boolean, T, F> = C extends true ? T : F;
|
||||
declare type Not<C extends boolean> = If<C, false, true>;
|
||||
declare type And<A extends boolean, B extends boolean> = If<A, B, false>;
|
||||
declare type Or<A extends boolean, B extends boolean> = If<A, true, B>;
|
||||
declare type isString<T> = Extends<T, string>;
|
||||
declare type Q1 = isString<number>;
|
||||
declare type Q2 = isString<"abc">;
|
||||
declare type Q3 = isString<any>;
|
||||
declare type Q4 = isString<never>;
|
||||
declare type N1 = Not<false>;
|
||||
declare type N2 = Not<true>;
|
||||
declare type N3 = Not<boolean>;
|
||||
declare type A1 = And<false, false>;
|
||||
declare type A2 = And<false, true>;
|
||||
declare type A3 = And<true, false>;
|
||||
declare type A4 = And<true, true>;
|
||||
declare type A5 = And<boolean, false>;
|
||||
declare type A6 = And<false, boolean>;
|
||||
declare type A7 = And<boolean, true>;
|
||||
declare type A8 = And<true, boolean>;
|
||||
declare type A9 = And<boolean, boolean>;
|
||||
declare type O1 = Or<false, false>;
|
||||
declare type O2 = Or<false, true>;
|
||||
declare type O3 = Or<true, false>;
|
||||
declare type O4 = Or<true, true>;
|
||||
declare type O5 = Or<boolean, false>;
|
||||
declare type O6 = Or<false, boolean>;
|
||||
declare type O7 = Or<boolean, true>;
|
||||
declare type O8 = Or<true, boolean>;
|
||||
declare type O9 = Or<boolean, boolean>;
|
||||
@@ -0,0 +1,753 @@
|
||||
=== tests/cases/conformance/types/conditional/conditionalTypes1.ts ===
|
||||
type Diff<T, U> = T extends U ? never : T;
|
||||
>Diff : Symbol(Diff, Decl(conditionalTypes1.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 0, 10))
|
||||
>U : Symbol(U, Decl(conditionalTypes1.ts, 0, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 0, 10))
|
||||
>U : Symbol(U, Decl(conditionalTypes1.ts, 0, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 0, 10))
|
||||
|
||||
type Filter<T, U> = T extends U ? T : never;
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 1, 12))
|
||||
>U : Symbol(U, Decl(conditionalTypes1.ts, 1, 14))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 1, 12))
|
||||
>U : Symbol(U, Decl(conditionalTypes1.ts, 1, 14))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 1, 12))
|
||||
|
||||
type NonNullable<T> = Diff<T, null | undefined>;
|
||||
>NonNullable : Symbol(NonNullable, Decl(conditionalTypes1.ts, 1, 44))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 2, 17))
|
||||
>Diff : Symbol(Diff, Decl(conditionalTypes1.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 2, 17))
|
||||
|
||||
type T00 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
|
||||
>T00 : Symbol(T00, Decl(conditionalTypes1.ts, 2, 48))
|
||||
>Diff : Symbol(Diff, Decl(conditionalTypes1.ts, 0, 0))
|
||||
|
||||
type T01 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
|
||||
>T01 : Symbol(T01, Decl(conditionalTypes1.ts, 4, 56))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
|
||||
type T02 = Diff<string | number | (() => void), Function>; // string | number
|
||||
>T02 : Symbol(T02, Decl(conditionalTypes1.ts, 5, 58))
|
||||
>Diff : Symbol(Diff, Decl(conditionalTypes1.ts, 0, 0))
|
||||
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
type T03 = Filter<string | number | (() => void), Function>; // () => void
|
||||
>T03 : Symbol(T03, Decl(conditionalTypes1.ts, 7, 58))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
type T04 = NonNullable<string | number | undefined>; // string | number
|
||||
>T04 : Symbol(T04, Decl(conditionalTypes1.ts, 8, 60))
|
||||
>NonNullable : Symbol(NonNullable, Decl(conditionalTypes1.ts, 1, 44))
|
||||
|
||||
type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
|
||||
>T05 : Symbol(T05, Decl(conditionalTypes1.ts, 10, 52))
|
||||
>NonNullable : Symbol(NonNullable, Decl(conditionalTypes1.ts, 1, 44))
|
||||
|
||||
function f1<T>(x: T, y: NonNullable<T>) {
|
||||
>f1 : Symbol(f1, Decl(conditionalTypes1.ts, 11, 69))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 13, 12))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 13, 15))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 13, 12))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 13, 20))
|
||||
>NonNullable : Symbol(NonNullable, Decl(conditionalTypes1.ts, 1, 44))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 13, 12))
|
||||
|
||||
x = y;
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 13, 15))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 13, 20))
|
||||
|
||||
y = x; // Error
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 13, 20))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 13, 15))
|
||||
}
|
||||
|
||||
function f2<T extends string | undefined>(x: T, y: NonNullable<T>) {
|
||||
>f2 : Symbol(f2, Decl(conditionalTypes1.ts, 16, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 18, 12))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 18, 42))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 18, 12))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 18, 47))
|
||||
>NonNullable : Symbol(NonNullable, Decl(conditionalTypes1.ts, 1, 44))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 18, 12))
|
||||
|
||||
x = y;
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 18, 42))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 18, 47))
|
||||
|
||||
y = x; // Error
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 18, 47))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 18, 42))
|
||||
|
||||
let s1: string = x; // Error
|
||||
>s1 : Symbol(s1, Decl(conditionalTypes1.ts, 21, 7))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 18, 42))
|
||||
|
||||
let s2: string = y;
|
||||
>s2 : Symbol(s2, Decl(conditionalTypes1.ts, 22, 7))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 18, 47))
|
||||
}
|
||||
|
||||
function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>) {
|
||||
>f3 : Symbol(f3, Decl(conditionalTypes1.ts, 23, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 25, 12))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 25, 15))
|
||||
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 25, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 25, 12))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 25, 38))
|
||||
>NonNullable : Symbol(NonNullable, Decl(conditionalTypes1.ts, 1, 44))
|
||||
>Partial : Symbol(Partial, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 25, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 25, 12))
|
||||
|
||||
x = y;
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 25, 15))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 25, 38))
|
||||
|
||||
y = x; // Error
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 25, 38))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 25, 15))
|
||||
}
|
||||
|
||||
type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean };
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 30, 16))
|
||||
>a : Symbol(a, Decl(conditionalTypes1.ts, 30, 24))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 30, 40))
|
||||
>b : Symbol(b, Decl(conditionalTypes1.ts, 30, 48))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 30, 64))
|
||||
>c : Symbol(c, Decl(conditionalTypes1.ts, 30, 72))
|
||||
|
||||
type T10 = Diff<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
|
||||
>T10 : Symbol(T10, Decl(conditionalTypes1.ts, 30, 86))
|
||||
>Diff : Symbol(Diff, Decl(conditionalTypes1.ts, 0, 0))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 32, 26))
|
||||
|
||||
type T11 = Filter<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T11 : Symbol(T11, Decl(conditionalTypes1.ts, 32, 43))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 33, 28))
|
||||
|
||||
type T12 = Diff<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
|
||||
>T12 : Symbol(T12, Decl(conditionalTypes1.ts, 33, 45))
|
||||
>Diff : Symbol(Diff, Decl(conditionalTypes1.ts, 0, 0))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 35, 26))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 35, 39))
|
||||
|
||||
type T13 = Filter<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T13 : Symbol(T13, Decl(conditionalTypes1.ts, 35, 50))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 36, 28))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 36, 41))
|
||||
|
||||
type T14 = Diff<Options, { q: "a" }>; // Options
|
||||
>T14 : Symbol(T14, Decl(conditionalTypes1.ts, 36, 52))
|
||||
>Diff : Symbol(Diff, Decl(conditionalTypes1.ts, 0, 0))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>q : Symbol(q, Decl(conditionalTypes1.ts, 38, 26))
|
||||
|
||||
type T15 = Filter<Options, { q: "a" }>; // never
|
||||
>T15 : Symbol(T15, Decl(conditionalTypes1.ts, 38, 37))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>q : Symbol(q, Decl(conditionalTypes1.ts, 39, 28))
|
||||
|
||||
declare function f4<T extends Options, K extends string>(p: K): Filter<T, { k: K }>;
|
||||
>f4 : Symbol(f4, Decl(conditionalTypes1.ts, 39, 39))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 41, 20))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 41, 38))
|
||||
>p : Symbol(p, Decl(conditionalTypes1.ts, 41, 57))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 41, 38))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 41, 20))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 41, 75))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 41, 38))
|
||||
|
||||
let x0 = f4("a"); // { k: "a", a: number }
|
||||
>x0 : Symbol(x0, Decl(conditionalTypes1.ts, 42, 3))
|
||||
>f4 : Symbol(f4, Decl(conditionalTypes1.ts, 39, 39))
|
||||
|
||||
type OptionsOfKind<K extends Options["k"]> = Filter<Options, { k: K }>;
|
||||
>OptionsOfKind : Symbol(OptionsOfKind, Decl(conditionalTypes1.ts, 42, 17))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 44, 19))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
>k : Symbol(k, Decl(conditionalTypes1.ts, 44, 62))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 44, 19))
|
||||
|
||||
type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T16 : Symbol(T16, Decl(conditionalTypes1.ts, 44, 71))
|
||||
>OptionsOfKind : Symbol(OptionsOfKind, Decl(conditionalTypes1.ts, 42, 17))
|
||||
|
||||
type Select<T, K extends keyof T, V extends T[K]> = Filter<T, { [P in K]: V }>;
|
||||
>Select : Symbol(Select, Decl(conditionalTypes1.ts, 46, 36))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 48, 12))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 48, 14))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 48, 12))
|
||||
>V : Symbol(V, Decl(conditionalTypes1.ts, 48, 33))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 48, 12))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 48, 14))
|
||||
>Filter : Symbol(Filter, Decl(conditionalTypes1.ts, 0, 42))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 48, 12))
|
||||
>P : Symbol(P, Decl(conditionalTypes1.ts, 48, 65))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 48, 14))
|
||||
>V : Symbol(V, Decl(conditionalTypes1.ts, 48, 33))
|
||||
|
||||
type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T17 : Symbol(T17, Decl(conditionalTypes1.ts, 48, 79))
|
||||
>Select : Symbol(Select, Decl(conditionalTypes1.ts, 46, 36))
|
||||
>Options : Symbol(Options, Decl(conditionalTypes1.ts, 28, 1))
|
||||
|
||||
type TypeName<T> =
|
||||
>TypeName : Symbol(TypeName, Decl(conditionalTypes1.ts, 50, 43))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 52, 14))
|
||||
|
||||
T extends string ? "string" :
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 52, 14))
|
||||
|
||||
T extends number ? "number" :
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 52, 14))
|
||||
|
||||
T extends boolean ? "boolean" :
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 52, 14))
|
||||
|
||||
T extends undefined ? "undefined" :
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 52, 14))
|
||||
|
||||
T extends Function ? "function" :
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 52, 14))
|
||||
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
"object";
|
||||
|
||||
type T20 = TypeName<string | (() => void)>; // "string" | "function"
|
||||
>T20 : Symbol(T20, Decl(conditionalTypes1.ts, 58, 13))
|
||||
>TypeName : Symbol(TypeName, Decl(conditionalTypes1.ts, 50, 43))
|
||||
|
||||
type T21 = TypeName<any>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
>T21 : Symbol(T21, Decl(conditionalTypes1.ts, 60, 43))
|
||||
>TypeName : Symbol(TypeName, Decl(conditionalTypes1.ts, 50, 43))
|
||||
|
||||
type T22 = TypeName<never>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
>T22 : Symbol(T22, Decl(conditionalTypes1.ts, 61, 25))
|
||||
>TypeName : Symbol(TypeName, Decl(conditionalTypes1.ts, 50, 43))
|
||||
|
||||
type T23 = TypeName<{}>; // "object"
|
||||
>T23 : Symbol(T23, Decl(conditionalTypes1.ts, 62, 27))
|
||||
>TypeName : Symbol(TypeName, Decl(conditionalTypes1.ts, 50, 43))
|
||||
|
||||
type KnockoutObservable<T> = { object: T };
|
||||
>KnockoutObservable : Symbol(KnockoutObservable, Decl(conditionalTypes1.ts, 63, 24))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 65, 24))
|
||||
>object : Symbol(object, Decl(conditionalTypes1.ts, 65, 30))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 65, 24))
|
||||
|
||||
type KnockoutObservableArray<T> = { array: T };
|
||||
>KnockoutObservableArray : Symbol(KnockoutObservableArray, Decl(conditionalTypes1.ts, 65, 43))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 66, 29))
|
||||
>array : Symbol(array, Decl(conditionalTypes1.ts, 66, 35))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 66, 29))
|
||||
|
||||
type KnockedOut<T> = T extends any[] ? KnockoutObservableArray<T[number]> : KnockoutObservable<T>;
|
||||
>KnockedOut : Symbol(KnockedOut, Decl(conditionalTypes1.ts, 66, 47))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 68, 16))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 68, 16))
|
||||
>KnockoutObservableArray : Symbol(KnockoutObservableArray, Decl(conditionalTypes1.ts, 65, 43))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 68, 16))
|
||||
>KnockoutObservable : Symbol(KnockoutObservable, Decl(conditionalTypes1.ts, 63, 24))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 68, 16))
|
||||
|
||||
type KnockedOutObj<T> = {
|
||||
>KnockedOutObj : Symbol(KnockedOutObj, Decl(conditionalTypes1.ts, 68, 98))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 70, 19))
|
||||
|
||||
[P in keyof T]: KnockedOut<T[P]>;
|
||||
>P : Symbol(P, Decl(conditionalTypes1.ts, 71, 5))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 70, 19))
|
||||
>KnockedOut : Symbol(KnockedOut, Decl(conditionalTypes1.ts, 66, 47))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 70, 19))
|
||||
>P : Symbol(P, Decl(conditionalTypes1.ts, 71, 5))
|
||||
}
|
||||
|
||||
interface Item {
|
||||
>Item : Symbol(Item, Decl(conditionalTypes1.ts, 72, 1))
|
||||
|
||||
id: number;
|
||||
>id : Symbol(Item.id, Decl(conditionalTypes1.ts, 74, 16))
|
||||
|
||||
name: string;
|
||||
>name : Symbol(Item.name, Decl(conditionalTypes1.ts, 75, 15))
|
||||
|
||||
subitems: string[];
|
||||
>subitems : Symbol(Item.subitems, Decl(conditionalTypes1.ts, 76, 17))
|
||||
}
|
||||
|
||||
type KOItem = KnockedOutObj<Item>;
|
||||
>KOItem : Symbol(KOItem, Decl(conditionalTypes1.ts, 78, 1))
|
||||
>KnockedOutObj : Symbol(KnockedOutObj, Decl(conditionalTypes1.ts, 68, 98))
|
||||
>Item : Symbol(Item, Decl(conditionalTypes1.ts, 72, 1))
|
||||
|
||||
interface Part {
|
||||
>Part : Symbol(Part, Decl(conditionalTypes1.ts, 80, 34))
|
||||
|
||||
id: number;
|
||||
>id : Symbol(Part.id, Decl(conditionalTypes1.ts, 82, 16))
|
||||
|
||||
name: string;
|
||||
>name : Symbol(Part.name, Decl(conditionalTypes1.ts, 83, 15))
|
||||
|
||||
subparts: Part[];
|
||||
>subparts : Symbol(Part.subparts, Decl(conditionalTypes1.ts, 84, 17))
|
||||
>Part : Symbol(Part, Decl(conditionalTypes1.ts, 80, 34))
|
||||
|
||||
updatePart(newName: string): void;
|
||||
>updatePart : Symbol(Part.updatePart, Decl(conditionalTypes1.ts, 85, 21))
|
||||
>newName : Symbol(newName, Decl(conditionalTypes1.ts, 86, 15))
|
||||
}
|
||||
|
||||
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
||||
>FunctionPropertyNames : Symbol(FunctionPropertyNames, Decl(conditionalTypes1.ts, 87, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 89, 27))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 89, 35))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 89, 27))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 89, 27))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 89, 35))
|
||||
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 89, 35))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 89, 27))
|
||||
|
||||
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
||||
>FunctionProperties : Symbol(FunctionProperties, Decl(conditionalTypes1.ts, 89, 95))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 90, 24))
|
||||
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 90, 24))
|
||||
>FunctionPropertyNames : Symbol(FunctionPropertyNames, Decl(conditionalTypes1.ts, 87, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 90, 24))
|
||||
|
||||
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
|
||||
>NonFunctionPropertyNames : Symbol(NonFunctionPropertyNames, Decl(conditionalTypes1.ts, 90, 63))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 92, 30))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 92, 38))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 92, 30))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 92, 30))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 92, 38))
|
||||
>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>K : Symbol(K, Decl(conditionalTypes1.ts, 92, 38))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 92, 30))
|
||||
|
||||
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
||||
>NonFunctionProperties : Symbol(NonFunctionProperties, Decl(conditionalTypes1.ts, 92, 98))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 93, 27))
|
||||
>Pick : Symbol(Pick, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 93, 27))
|
||||
>NonFunctionPropertyNames : Symbol(NonFunctionPropertyNames, Decl(conditionalTypes1.ts, 90, 63))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 93, 27))
|
||||
|
||||
type T30 = FunctionProperties<Part>;
|
||||
>T30 : Symbol(T30, Decl(conditionalTypes1.ts, 93, 69))
|
||||
>FunctionProperties : Symbol(FunctionProperties, Decl(conditionalTypes1.ts, 89, 95))
|
||||
>Part : Symbol(Part, Decl(conditionalTypes1.ts, 80, 34))
|
||||
|
||||
type T31 = NonFunctionProperties<Part>;
|
||||
>T31 : Symbol(T31, Decl(conditionalTypes1.ts, 95, 36))
|
||||
>NonFunctionProperties : Symbol(NonFunctionProperties, Decl(conditionalTypes1.ts, 92, 98))
|
||||
>Part : Symbol(Part, Decl(conditionalTypes1.ts, 80, 34))
|
||||
|
||||
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
|
||||
>f7 : Symbol(f7, Decl(conditionalTypes1.ts, 96, 39))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 98, 12))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 98, 15))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 98, 12))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 98, 20))
|
||||
>FunctionProperties : Symbol(FunctionProperties, Decl(conditionalTypes1.ts, 89, 95))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 98, 12))
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 98, 46))
|
||||
>NonFunctionProperties : Symbol(NonFunctionProperties, Decl(conditionalTypes1.ts, 92, 98))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 98, 12))
|
||||
|
||||
x = y; // Error
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 98, 15))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 98, 20))
|
||||
|
||||
x = z; // Error
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 98, 15))
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 98, 46))
|
||||
|
||||
y = x;
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 98, 20))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 98, 15))
|
||||
|
||||
y = z; // Error
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 98, 20))
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 98, 46))
|
||||
|
||||
z = x;
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 98, 46))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 98, 15))
|
||||
|
||||
z = y; // Error
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 98, 46))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 98, 20))
|
||||
}
|
||||
|
||||
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
|
||||
>f8 : Symbol(f8, Decl(conditionalTypes1.ts, 105, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 107, 12))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 107, 15))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 107, 12))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 107, 26))
|
||||
>FunctionPropertyNames : Symbol(FunctionPropertyNames, Decl(conditionalTypes1.ts, 87, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 107, 12))
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 107, 55))
|
||||
>NonFunctionPropertyNames : Symbol(NonFunctionPropertyNames, Decl(conditionalTypes1.ts, 90, 63))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 107, 12))
|
||||
|
||||
x = y;
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 107, 15))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 107, 26))
|
||||
|
||||
x = z;
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 107, 15))
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 107, 55))
|
||||
|
||||
y = x; // Error
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 107, 26))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 107, 15))
|
||||
|
||||
y = z; // Error
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 107, 26))
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 107, 55))
|
||||
|
||||
z = x; // Error
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 107, 55))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 107, 15))
|
||||
|
||||
z = y; // Error
|
||||
>z : Symbol(z, Decl(conditionalTypes1.ts, 107, 55))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 107, 26))
|
||||
}
|
||||
|
||||
type DeepReadonly<T> =
|
||||
>DeepReadonly : Symbol(DeepReadonly, Decl(conditionalTypes1.ts, 114, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 116, 18))
|
||||
|
||||
T extends any[] ? DeepReadonlyArray<T[number]> :
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 116, 18))
|
||||
>DeepReadonlyArray : Symbol(DeepReadonlyArray, Decl(conditionalTypes1.ts, 119, 6))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 116, 18))
|
||||
|
||||
T extends object ? DeepReadonlyObject<T> :
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 116, 18))
|
||||
>DeepReadonlyObject : Symbol(DeepReadonlyObject, Decl(conditionalTypes1.ts, 121, 72))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 116, 18))
|
||||
|
||||
T;
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 116, 18))
|
||||
|
||||
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
|
||||
>DeepReadonlyArray : Symbol(DeepReadonlyArray, Decl(conditionalTypes1.ts, 119, 6))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 121, 28))
|
||||
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.d.ts, --, --))
|
||||
>DeepReadonly : Symbol(DeepReadonly, Decl(conditionalTypes1.ts, 114, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 121, 28))
|
||||
|
||||
type DeepReadonlyObject<T> = {
|
||||
>DeepReadonlyObject : Symbol(DeepReadonlyObject, Decl(conditionalTypes1.ts, 121, 72))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 123, 24))
|
||||
|
||||
readonly [P in NonFunctionPropertyNames<T>]: DeepReadonly<T[P]>;
|
||||
>P : Symbol(P, Decl(conditionalTypes1.ts, 124, 14))
|
||||
>NonFunctionPropertyNames : Symbol(NonFunctionPropertyNames, Decl(conditionalTypes1.ts, 90, 63))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 123, 24))
|
||||
>DeepReadonly : Symbol(DeepReadonly, Decl(conditionalTypes1.ts, 114, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 123, 24))
|
||||
>P : Symbol(P, Decl(conditionalTypes1.ts, 124, 14))
|
||||
|
||||
};
|
||||
|
||||
function f10(part: DeepReadonly<Part>) {
|
||||
>f10 : Symbol(f10, Decl(conditionalTypes1.ts, 125, 2))
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>DeepReadonly : Symbol(DeepReadonly, Decl(conditionalTypes1.ts, 114, 1))
|
||||
>Part : Symbol(Part, Decl(conditionalTypes1.ts, 80, 34))
|
||||
|
||||
let name: string = part.name;
|
||||
>name : Symbol(name, Decl(conditionalTypes1.ts, 128, 7))
|
||||
>part.name : Symbol(name)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>name : Symbol(name)
|
||||
|
||||
let id: number = part.subparts[0].id;
|
||||
>id : Symbol(id, Decl(conditionalTypes1.ts, 129, 7))
|
||||
>part.subparts[0].id : Symbol(id)
|
||||
>part.subparts : Symbol(subparts)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>subparts : Symbol(subparts)
|
||||
>id : Symbol(id)
|
||||
|
||||
part.id = part.id; // Error
|
||||
>part.id : Symbol(id)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>id : Symbol(id)
|
||||
>part.id : Symbol(id)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>id : Symbol(id)
|
||||
|
||||
part.subparts[0] = part.subparts[0]; // Error
|
||||
>part.subparts : Symbol(subparts)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>subparts : Symbol(subparts)
|
||||
>part.subparts : Symbol(subparts)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>subparts : Symbol(subparts)
|
||||
|
||||
part.subparts[0].id = part.subparts[0].id; // Error
|
||||
>part.subparts[0].id : Symbol(id)
|
||||
>part.subparts : Symbol(subparts)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>subparts : Symbol(subparts)
|
||||
>id : Symbol(id)
|
||||
>part.subparts[0].id : Symbol(id)
|
||||
>part.subparts : Symbol(subparts)
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
>subparts : Symbol(subparts)
|
||||
>id : Symbol(id)
|
||||
|
||||
part.updatePart("hello"); // Error
|
||||
>part : Symbol(part, Decl(conditionalTypes1.ts, 127, 13))
|
||||
}
|
||||
|
||||
type ZeroOf<T extends number | string | boolean> = T extends number ? 0 : T extends string ? "" : false;
|
||||
>ZeroOf : Symbol(ZeroOf, Decl(conditionalTypes1.ts, 134, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 136, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 136, 12))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 136, 12))
|
||||
|
||||
function zeroOf<T extends number | string | boolean>(value: T) {
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 138, 16))
|
||||
>value : Symbol(value, Decl(conditionalTypes1.ts, 138, 53))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 138, 16))
|
||||
|
||||
return <ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
|
||||
>ZeroOf : Symbol(ZeroOf, Decl(conditionalTypes1.ts, 134, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 138, 16))
|
||||
>value : Symbol(value, Decl(conditionalTypes1.ts, 138, 53))
|
||||
>value : Symbol(value, Decl(conditionalTypes1.ts, 138, 53))
|
||||
}
|
||||
|
||||
function f20<T extends string>(n: number, b: boolean, x: number | boolean, y: T) {
|
||||
>f20 : Symbol(f20, Decl(conditionalTypes1.ts, 140, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 142, 13))
|
||||
>n : Symbol(n, Decl(conditionalTypes1.ts, 142, 31))
|
||||
>b : Symbol(b, Decl(conditionalTypes1.ts, 142, 41))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 142, 53))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 142, 74))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 142, 13))
|
||||
|
||||
zeroOf(5); // 0
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
|
||||
zeroOf("hello"); // ""
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
|
||||
zeroOf(true); // false
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
|
||||
zeroOf(n); // 0
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
>n : Symbol(n, Decl(conditionalTypes1.ts, 142, 31))
|
||||
|
||||
zeroOf(b); // False
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
>b : Symbol(b, Decl(conditionalTypes1.ts, 142, 41))
|
||||
|
||||
zeroOf(x); // 0 | false
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 142, 53))
|
||||
|
||||
zeroOf(y); // ZeroOf<T>
|
||||
>zeroOf : Symbol(zeroOf, Decl(conditionalTypes1.ts, 136, 104))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 142, 74))
|
||||
}
|
||||
|
||||
function f21<T extends number | string>(x: T, y: ZeroOf<T>) {
|
||||
>f21 : Symbol(f21, Decl(conditionalTypes1.ts, 150, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 152, 13))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 152, 40))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 152, 13))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 152, 45))
|
||||
>ZeroOf : Symbol(ZeroOf, Decl(conditionalTypes1.ts, 134, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 152, 13))
|
||||
|
||||
let z1: number | string = y;
|
||||
>z1 : Symbol(z1, Decl(conditionalTypes1.ts, 153, 7))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 152, 45))
|
||||
|
||||
let z2: 0 | "" = y;
|
||||
>z2 : Symbol(z2, Decl(conditionalTypes1.ts, 154, 7))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 152, 45))
|
||||
|
||||
x = y; // Error
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 152, 40))
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 152, 45))
|
||||
|
||||
y = x; // Error
|
||||
>y : Symbol(y, Decl(conditionalTypes1.ts, 152, 45))
|
||||
>x : Symbol(x, Decl(conditionalTypes1.ts, 152, 40))
|
||||
}
|
||||
|
||||
type Extends<T, U> = T extends U ? true : false;
|
||||
>Extends : Symbol(Extends, Decl(conditionalTypes1.ts, 157, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 159, 13))
|
||||
>U : Symbol(U, Decl(conditionalTypes1.ts, 159, 15))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 159, 13))
|
||||
>U : Symbol(U, Decl(conditionalTypes1.ts, 159, 15))
|
||||
|
||||
type If<C extends boolean, T, F> = C extends true ? T : F;
|
||||
>If : Symbol(If, Decl(conditionalTypes1.ts, 159, 48))
|
||||
>C : Symbol(C, Decl(conditionalTypes1.ts, 160, 8))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 160, 26))
|
||||
>F : Symbol(F, Decl(conditionalTypes1.ts, 160, 29))
|
||||
>C : Symbol(C, Decl(conditionalTypes1.ts, 160, 8))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 160, 26))
|
||||
>F : Symbol(F, Decl(conditionalTypes1.ts, 160, 29))
|
||||
|
||||
type Not<C extends boolean> = If<C, false, true>;
|
||||
>Not : Symbol(Not, Decl(conditionalTypes1.ts, 160, 58))
|
||||
>C : Symbol(C, Decl(conditionalTypes1.ts, 161, 9))
|
||||
>If : Symbol(If, Decl(conditionalTypes1.ts, 159, 48))
|
||||
>C : Symbol(C, Decl(conditionalTypes1.ts, 161, 9))
|
||||
|
||||
type And<A extends boolean, B extends boolean> = If<A, B, false>;
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
>A : Symbol(A, Decl(conditionalTypes1.ts, 162, 9))
|
||||
>B : Symbol(B, Decl(conditionalTypes1.ts, 162, 27))
|
||||
>If : Symbol(If, Decl(conditionalTypes1.ts, 159, 48))
|
||||
>A : Symbol(A, Decl(conditionalTypes1.ts, 162, 9))
|
||||
>B : Symbol(B, Decl(conditionalTypes1.ts, 162, 27))
|
||||
|
||||
type Or<A extends boolean, B extends boolean> = If<A, true, B>;
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
>A : Symbol(A, Decl(conditionalTypes1.ts, 163, 8))
|
||||
>B : Symbol(B, Decl(conditionalTypes1.ts, 163, 26))
|
||||
>If : Symbol(If, Decl(conditionalTypes1.ts, 159, 48))
|
||||
>A : Symbol(A, Decl(conditionalTypes1.ts, 163, 8))
|
||||
>B : Symbol(B, Decl(conditionalTypes1.ts, 163, 26))
|
||||
|
||||
type isString<T> = Extends<T, string>;
|
||||
>isString : Symbol(isString, Decl(conditionalTypes1.ts, 163, 63))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 165, 14))
|
||||
>Extends : Symbol(Extends, Decl(conditionalTypes1.ts, 157, 1))
|
||||
>T : Symbol(T, Decl(conditionalTypes1.ts, 165, 14))
|
||||
|
||||
type Q1 = isString<number>; // false
|
||||
>Q1 : Symbol(Q1, Decl(conditionalTypes1.ts, 165, 38))
|
||||
>isString : Symbol(isString, Decl(conditionalTypes1.ts, 163, 63))
|
||||
|
||||
type Q2 = isString<"abc">; // true
|
||||
>Q2 : Symbol(Q2, Decl(conditionalTypes1.ts, 167, 27))
|
||||
>isString : Symbol(isString, Decl(conditionalTypes1.ts, 163, 63))
|
||||
|
||||
type Q3 = isString<any>; // boolean
|
||||
>Q3 : Symbol(Q3, Decl(conditionalTypes1.ts, 168, 26))
|
||||
>isString : Symbol(isString, Decl(conditionalTypes1.ts, 163, 63))
|
||||
|
||||
type Q4 = isString<never>; // boolean
|
||||
>Q4 : Symbol(Q4, Decl(conditionalTypes1.ts, 169, 24))
|
||||
>isString : Symbol(isString, Decl(conditionalTypes1.ts, 163, 63))
|
||||
|
||||
type N1 = Not<false>; // true
|
||||
>N1 : Symbol(N1, Decl(conditionalTypes1.ts, 170, 26))
|
||||
>Not : Symbol(Not, Decl(conditionalTypes1.ts, 160, 58))
|
||||
|
||||
type N2 = Not<true>; // false
|
||||
>N2 : Symbol(N2, Decl(conditionalTypes1.ts, 172, 21))
|
||||
>Not : Symbol(Not, Decl(conditionalTypes1.ts, 160, 58))
|
||||
|
||||
type N3 = Not<boolean>; // boolean
|
||||
>N3 : Symbol(N3, Decl(conditionalTypes1.ts, 173, 20))
|
||||
>Not : Symbol(Not, Decl(conditionalTypes1.ts, 160, 58))
|
||||
|
||||
type A1 = And<false, false>; // false
|
||||
>A1 : Symbol(A1, Decl(conditionalTypes1.ts, 174, 23))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A2 = And<false, true>; // false
|
||||
>A2 : Symbol(A2, Decl(conditionalTypes1.ts, 176, 28))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A3 = And<true, false>; // false
|
||||
>A3 : Symbol(A3, Decl(conditionalTypes1.ts, 177, 27))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A4 = And<true, true>; // true
|
||||
>A4 : Symbol(A4, Decl(conditionalTypes1.ts, 178, 27))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A5 = And<boolean, false>; // false
|
||||
>A5 : Symbol(A5, Decl(conditionalTypes1.ts, 179, 26))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A6 = And<false, boolean>; // false
|
||||
>A6 : Symbol(A6, Decl(conditionalTypes1.ts, 180, 30))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A7 = And<boolean, true>; // boolean
|
||||
>A7 : Symbol(A7, Decl(conditionalTypes1.ts, 181, 30))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A8 = And<true, boolean>; // boolean
|
||||
>A8 : Symbol(A8, Decl(conditionalTypes1.ts, 182, 29))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type A9 = And<boolean, boolean>; // boolean
|
||||
>A9 : Symbol(A9, Decl(conditionalTypes1.ts, 183, 29))
|
||||
>And : Symbol(And, Decl(conditionalTypes1.ts, 161, 49))
|
||||
|
||||
type O1 = Or<false, false>; // false
|
||||
>O1 : Symbol(O1, Decl(conditionalTypes1.ts, 184, 32))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O2 = Or<false, true>; // true
|
||||
>O2 : Symbol(O2, Decl(conditionalTypes1.ts, 186, 27))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O3 = Or<true, false>; // true
|
||||
>O3 : Symbol(O3, Decl(conditionalTypes1.ts, 187, 26))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O4 = Or<true, true>; // true
|
||||
>O4 : Symbol(O4, Decl(conditionalTypes1.ts, 188, 26))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O5 = Or<boolean, false>; // boolean
|
||||
>O5 : Symbol(O5, Decl(conditionalTypes1.ts, 189, 25))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O6 = Or<false, boolean>; // boolean
|
||||
>O6 : Symbol(O6, Decl(conditionalTypes1.ts, 190, 29))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O7 = Or<boolean, true>; // true
|
||||
>O7 : Symbol(O7, Decl(conditionalTypes1.ts, 191, 29))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O8 = Or<true, boolean>; // true
|
||||
>O8 : Symbol(O8, Decl(conditionalTypes1.ts, 192, 28))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
type O9 = Or<boolean, boolean>; // boolean
|
||||
>O9 : Symbol(O9, Decl(conditionalTypes1.ts, 193, 28))
|
||||
>Or : Symbol(Or, Decl(conditionalTypes1.ts, 162, 65))
|
||||
|
||||
@@ -0,0 +1,851 @@
|
||||
=== tests/cases/conformance/types/conditional/conditionalTypes1.ts ===
|
||||
type Diff<T, U> = T extends U ? never : T;
|
||||
>Diff : Diff<T, U>
|
||||
>T : T
|
||||
>U : U
|
||||
>T : T
|
||||
>U : U
|
||||
>T : T
|
||||
|
||||
type Filter<T, U> = T extends U ? T : never;
|
||||
>Filter : Filter<T, U>
|
||||
>T : T
|
||||
>U : U
|
||||
>T : T
|
||||
>U : U
|
||||
>T : T
|
||||
|
||||
type NonNullable<T> = Diff<T, null | undefined>;
|
||||
>NonNullable : Diff<T, null | undefined>
|
||||
>T : T
|
||||
>Diff : Diff<T, U>
|
||||
>T : T
|
||||
>null : null
|
||||
|
||||
type T00 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
|
||||
>T00 : "b" | "d"
|
||||
>Diff : Diff<T, U>
|
||||
|
||||
type T01 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
|
||||
>T01 : "a" | "c"
|
||||
>Filter : Filter<T, U>
|
||||
|
||||
type T02 = Diff<string | number | (() => void), Function>; // string | number
|
||||
>T02 : string | number
|
||||
>Diff : Diff<T, U>
|
||||
>Function : Function
|
||||
|
||||
type T03 = Filter<string | number | (() => void), Function>; // () => void
|
||||
>T03 : () => void
|
||||
>Filter : Filter<T, U>
|
||||
>Function : Function
|
||||
|
||||
type T04 = NonNullable<string | number | undefined>; // string | number
|
||||
>T04 : string | number
|
||||
>NonNullable : Diff<T, null | undefined>
|
||||
|
||||
type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
|
||||
>T05 : (() => string) | string[]
|
||||
>NonNullable : Diff<T, null | undefined>
|
||||
>null : null
|
||||
|
||||
function f1<T>(x: T, y: NonNullable<T>) {
|
||||
>f1 : <T>(x: T, y: Diff<T, null | undefined>) => void
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>y : Diff<T, null | undefined>
|
||||
>NonNullable : Diff<T, null | undefined>
|
||||
>T : T
|
||||
|
||||
x = y;
|
||||
>x = y : Diff<T, null | undefined>
|
||||
>x : T
|
||||
>y : Diff<T, null | undefined>
|
||||
|
||||
y = x; // Error
|
||||
>y = x : T
|
||||
>y : Diff<T, null | undefined>
|
||||
>x : T
|
||||
}
|
||||
|
||||
function f2<T extends string | undefined>(x: T, y: NonNullable<T>) {
|
||||
>f2 : <T extends string | undefined>(x: T, y: Diff<T, null | undefined>) => void
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>y : Diff<T, null | undefined>
|
||||
>NonNullable : Diff<T, null | undefined>
|
||||
>T : T
|
||||
|
||||
x = y;
|
||||
>x = y : Diff<T, null | undefined>
|
||||
>x : T
|
||||
>y : Diff<T, null | undefined>
|
||||
|
||||
y = x; // Error
|
||||
>y = x : T
|
||||
>y : Diff<T, null | undefined>
|
||||
>x : T
|
||||
|
||||
let s1: string = x; // Error
|
||||
>s1 : string
|
||||
>x : T
|
||||
|
||||
let s2: string = y;
|
||||
>s2 : string
|
||||
>y : Diff<T, null | undefined>
|
||||
}
|
||||
|
||||
function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>) {
|
||||
>f3 : <T>(x: Partial<T>[keyof T], y: Diff<Partial<T>[keyof T], null | undefined>) => void
|
||||
>T : T
|
||||
>x : Partial<T>[keyof T]
|
||||
>Partial : Partial<T>
|
||||
>T : T
|
||||
>T : T
|
||||
>y : Diff<Partial<T>[keyof T], null | undefined>
|
||||
>NonNullable : Diff<T, null | undefined>
|
||||
>Partial : Partial<T>
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
x = y;
|
||||
>x = y : Diff<Partial<T>[keyof T], null | undefined>
|
||||
>x : Partial<T>[keyof T]
|
||||
>y : Diff<Partial<T>[keyof T], null | undefined>
|
||||
|
||||
y = x; // Error
|
||||
>y = x : Partial<T>[keyof T]
|
||||
>y : Diff<Partial<T>[keyof T], null | undefined>
|
||||
>x : Partial<T>[keyof T]
|
||||
}
|
||||
|
||||
type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean };
|
||||
>Options : Options
|
||||
>k : "a"
|
||||
>a : number
|
||||
>k : "b"
|
||||
>b : string
|
||||
>k : "c"
|
||||
>c : boolean
|
||||
|
||||
type T10 = Diff<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
|
||||
>T10 : { k: "c"; c: boolean; }
|
||||
>Diff : Diff<T, U>
|
||||
>Options : Options
|
||||
>k : "a" | "b"
|
||||
|
||||
type T11 = Filter<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T11 : { k: "a"; a: number; } | { k: "b"; b: string; }
|
||||
>Filter : Filter<T, U>
|
||||
>Options : Options
|
||||
>k : "a" | "b"
|
||||
|
||||
type T12 = Diff<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
|
||||
>T12 : { k: "c"; c: boolean; }
|
||||
>Diff : Diff<T, U>
|
||||
>Options : Options
|
||||
>k : "a"
|
||||
>k : "b"
|
||||
|
||||
type T13 = Filter<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T13 : { k: "a"; a: number; } | { k: "b"; b: string; }
|
||||
>Filter : Filter<T, U>
|
||||
>Options : Options
|
||||
>k : "a"
|
||||
>k : "b"
|
||||
|
||||
type T14 = Diff<Options, { q: "a" }>; // Options
|
||||
>T14 : Options
|
||||
>Diff : Diff<T, U>
|
||||
>Options : Options
|
||||
>q : "a"
|
||||
|
||||
type T15 = Filter<Options, { q: "a" }>; // never
|
||||
>T15 : never
|
||||
>Filter : Filter<T, U>
|
||||
>Options : Options
|
||||
>q : "a"
|
||||
|
||||
declare function f4<T extends Options, K extends string>(p: K): Filter<T, { k: K }>;
|
||||
>f4 : <T extends Options, K extends string>(p: K) => Filter<T, { k: K; }>
|
||||
>T : T
|
||||
>Options : Options
|
||||
>K : K
|
||||
>p : K
|
||||
>K : K
|
||||
>Filter : Filter<T, U>
|
||||
>T : T
|
||||
>k : K
|
||||
>K : K
|
||||
|
||||
let x0 = f4("a"); // { k: "a", a: number }
|
||||
>x0 : { k: "a"; a: number; }
|
||||
>f4("a") : { k: "a"; a: number; }
|
||||
>f4 : <T extends Options, K extends string>(p: K) => Filter<T, { k: K; }>
|
||||
>"a" : "a"
|
||||
|
||||
type OptionsOfKind<K extends Options["k"]> = Filter<Options, { k: K }>;
|
||||
>OptionsOfKind : Filter<{ k: "a"; a: number; }, { k: K; }> | Filter<{ k: "b"; b: string; }, { k: K; }> | Filter<{ k: "c"; c: boolean; }, { k: K; }>
|
||||
>K : K
|
||||
>Options : Options
|
||||
>Filter : Filter<T, U>
|
||||
>Options : Options
|
||||
>k : K
|
||||
>K : K
|
||||
|
||||
type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T16 : { k: "a"; a: number; } | { k: "b"; b: string; }
|
||||
>OptionsOfKind : Filter<{ k: "a"; a: number; }, { k: K; }> | Filter<{ k: "b"; b: string; }, { k: K; }> | Filter<{ k: "c"; c: boolean; }, { k: K; }>
|
||||
|
||||
type Select<T, K extends keyof T, V extends T[K]> = Filter<T, { [P in K]: V }>;
|
||||
>Select : Filter<T, { [P in K]: V; }>
|
||||
>T : T
|
||||
>K : K
|
||||
>T : T
|
||||
>V : V
|
||||
>T : T
|
||||
>K : K
|
||||
>Filter : Filter<T, U>
|
||||
>T : T
|
||||
>P : P
|
||||
>K : K
|
||||
>V : V
|
||||
|
||||
type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
|
||||
>T17 : { k: "a"; a: number; } | { k: "b"; b: string; }
|
||||
>Select : Filter<T, { [P in K]: V; }>
|
||||
>Options : Options
|
||||
|
||||
type TypeName<T> =
|
||||
>TypeName : TypeName<T>
|
||||
>T : T
|
||||
|
||||
T extends string ? "string" :
|
||||
>T : T
|
||||
|
||||
T extends number ? "number" :
|
||||
>T : T
|
||||
|
||||
T extends boolean ? "boolean" :
|
||||
>T : T
|
||||
|
||||
T extends undefined ? "undefined" :
|
||||
>T : T
|
||||
|
||||
T extends Function ? "function" :
|
||||
>T : T
|
||||
>Function : Function
|
||||
|
||||
"object";
|
||||
|
||||
type T20 = TypeName<string | (() => void)>; // "string" | "function"
|
||||
>T20 : "string" | "function"
|
||||
>TypeName : TypeName<T>
|
||||
|
||||
type T21 = TypeName<any>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
>T21 : "string" | "number" | "boolean" | "undefined" | "object" | "function"
|
||||
>TypeName : TypeName<T>
|
||||
|
||||
type T22 = TypeName<never>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
>T22 : "string" | "number" | "boolean" | "undefined" | "object" | "function"
|
||||
>TypeName : TypeName<T>
|
||||
|
||||
type T23 = TypeName<{}>; // "object"
|
||||
>T23 : "object"
|
||||
>TypeName : TypeName<T>
|
||||
|
||||
type KnockoutObservable<T> = { object: T };
|
||||
>KnockoutObservable : KnockoutObservable<T>
|
||||
>T : T
|
||||
>object : T
|
||||
>T : T
|
||||
|
||||
type KnockoutObservableArray<T> = { array: T };
|
||||
>KnockoutObservableArray : KnockoutObservableArray<T>
|
||||
>T : T
|
||||
>array : T
|
||||
>T : T
|
||||
|
||||
type KnockedOut<T> = T extends any[] ? KnockoutObservableArray<T[number]> : KnockoutObservable<T>;
|
||||
>KnockedOut : KnockedOut<T>
|
||||
>T : T
|
||||
>T : T
|
||||
>KnockoutObservableArray : KnockoutObservableArray<T>
|
||||
>T : T
|
||||
>KnockoutObservable : KnockoutObservable<T>
|
||||
>T : T
|
||||
|
||||
type KnockedOutObj<T> = {
|
||||
>KnockedOutObj : KnockedOutObj<T>
|
||||
>T : T
|
||||
|
||||
[P in keyof T]: KnockedOut<T[P]>;
|
||||
>P : P
|
||||
>T : T
|
||||
>KnockedOut : KnockedOut<T>
|
||||
>T : T
|
||||
>P : P
|
||||
}
|
||||
|
||||
interface Item {
|
||||
>Item : Item
|
||||
|
||||
id: number;
|
||||
>id : number
|
||||
|
||||
name: string;
|
||||
>name : string
|
||||
|
||||
subitems: string[];
|
||||
>subitems : string[]
|
||||
}
|
||||
|
||||
type KOItem = KnockedOutObj<Item>;
|
||||
>KOItem : KnockedOutObj<Item>
|
||||
>KnockedOutObj : KnockedOutObj<T>
|
||||
>Item : Item
|
||||
|
||||
interface Part {
|
||||
>Part : Part
|
||||
|
||||
id: number;
|
||||
>id : number
|
||||
|
||||
name: string;
|
||||
>name : string
|
||||
|
||||
subparts: Part[];
|
||||
>subparts : Part[]
|
||||
>Part : Part
|
||||
|
||||
updatePart(newName: string): void;
|
||||
>updatePart : (newName: string) => void
|
||||
>newName : string
|
||||
}
|
||||
|
||||
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
||||
>FunctionPropertyNames : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>T : T
|
||||
>K : K
|
||||
>T : T
|
||||
>T : T
|
||||
>K : K
|
||||
>Function : Function
|
||||
>K : K
|
||||
>T : T
|
||||
|
||||
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
||||
>FunctionProperties : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>T : T
|
||||
>Pick : Pick<T, K>
|
||||
>T : T
|
||||
>FunctionPropertyNames : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>T : T
|
||||
|
||||
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
|
||||
>NonFunctionPropertyNames : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>T : T
|
||||
>K : K
|
||||
>T : T
|
||||
>T : T
|
||||
>K : K
|
||||
>Function : Function
|
||||
>K : K
|
||||
>T : T
|
||||
|
||||
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
||||
>NonFunctionProperties : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>T : T
|
||||
>Pick : Pick<T, K>
|
||||
>T : T
|
||||
>NonFunctionPropertyNames : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>T : T
|
||||
|
||||
type T30 = FunctionProperties<Part>;
|
||||
>T30 : Pick<Part, "updatePart">
|
||||
>FunctionProperties : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>Part : Part
|
||||
|
||||
type T31 = NonFunctionProperties<Part>;
|
||||
>T31 : Pick<Part, "id" | "name" | "subparts">
|
||||
>NonFunctionProperties : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>Part : Part
|
||||
|
||||
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
|
||||
>f7 : <T>(x: T, y: Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>, z: Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>) => void
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>y : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>FunctionProperties : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>T : T
|
||||
>z : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>NonFunctionProperties : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>T : T
|
||||
|
||||
x = y; // Error
|
||||
>x = y : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>x : T
|
||||
>y : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
|
||||
x = z; // Error
|
||||
>x = z : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>x : T
|
||||
>z : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
|
||||
y = x;
|
||||
>y = x : T
|
||||
>y : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>x : T
|
||||
|
||||
y = z; // Error
|
||||
>y = z : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>y : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>z : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
|
||||
z = x;
|
||||
>z = x : T
|
||||
>z : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>x : T
|
||||
|
||||
z = y; // Error
|
||||
>z = y : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
>z : Pick<T, { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]>
|
||||
>y : Pick<T, { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]>
|
||||
}
|
||||
|
||||
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
|
||||
>f8 : <T>(x: keyof T, y: { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T], z: { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]) => void
|
||||
>T : T
|
||||
>x : keyof T
|
||||
>T : T
|
||||
>y : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>FunctionPropertyNames : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>T : T
|
||||
>z : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>NonFunctionPropertyNames : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>T : T
|
||||
|
||||
x = y;
|
||||
>x = y : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>x : keyof T
|
||||
>y : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
|
||||
x = z;
|
||||
>x = z : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>x : keyof T
|
||||
>z : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
|
||||
y = x; // Error
|
||||
>y = x : keyof T
|
||||
>y : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>x : keyof T
|
||||
|
||||
y = z; // Error
|
||||
>y = z : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>y : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>z : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
|
||||
z = x; // Error
|
||||
>z = x : keyof T
|
||||
>z : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>x : keyof T
|
||||
|
||||
z = y; // Error
|
||||
>z = y : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
>z : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>y : { [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]
|
||||
}
|
||||
|
||||
type DeepReadonly<T> =
|
||||
>DeepReadonly : DeepReadonly<T>
|
||||
>T : T
|
||||
|
||||
T extends any[] ? DeepReadonlyArray<T[number]> :
|
||||
>T : T
|
||||
>DeepReadonlyArray : DeepReadonlyArray<T>
|
||||
>T : T
|
||||
|
||||
T extends object ? DeepReadonlyObject<T> :
|
||||
>T : T
|
||||
>DeepReadonlyObject : DeepReadonlyObject<T>
|
||||
>T : T
|
||||
|
||||
T;
|
||||
>T : T
|
||||
|
||||
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
|
||||
>DeepReadonlyArray : DeepReadonlyArray<T>
|
||||
>T : T
|
||||
>ReadonlyArray : ReadonlyArray<T>
|
||||
>DeepReadonly : DeepReadonly<T>
|
||||
>T : T
|
||||
|
||||
type DeepReadonlyObject<T> = {
|
||||
>DeepReadonlyObject : DeepReadonlyObject<T>
|
||||
>T : T
|
||||
|
||||
readonly [P in NonFunctionPropertyNames<T>]: DeepReadonly<T[P]>;
|
||||
>P : P
|
||||
>NonFunctionPropertyNames : { [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]
|
||||
>T : T
|
||||
>DeepReadonly : DeepReadonly<T>
|
||||
>T : T
|
||||
>P : P
|
||||
|
||||
};
|
||||
|
||||
function f10(part: DeepReadonly<Part>) {
|
||||
>f10 : (part: DeepReadonlyObject<Part>) => void
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>DeepReadonly : DeepReadonly<T>
|
||||
>Part : Part
|
||||
|
||||
let name: string = part.name;
|
||||
>name : string
|
||||
>part.name : string
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>name : string
|
||||
|
||||
let id: number = part.subparts[0].id;
|
||||
>id : number
|
||||
>part.subparts[0].id : number
|
||||
>part.subparts[0] : DeepReadonlyObject<Part>
|
||||
>part.subparts : DeepReadonlyArray<Part>
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>subparts : DeepReadonlyArray<Part>
|
||||
>0 : 0
|
||||
>id : number
|
||||
|
||||
part.id = part.id; // Error
|
||||
>part.id = part.id : number
|
||||
>part.id : any
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>id : any
|
||||
>part.id : number
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>id : number
|
||||
|
||||
part.subparts[0] = part.subparts[0]; // Error
|
||||
>part.subparts[0] = part.subparts[0] : DeepReadonlyObject<Part>
|
||||
>part.subparts[0] : DeepReadonlyObject<Part>
|
||||
>part.subparts : DeepReadonlyArray<Part>
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>subparts : DeepReadonlyArray<Part>
|
||||
>0 : 0
|
||||
>part.subparts[0] : DeepReadonlyObject<Part>
|
||||
>part.subparts : DeepReadonlyArray<Part>
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>subparts : DeepReadonlyArray<Part>
|
||||
>0 : 0
|
||||
|
||||
part.subparts[0].id = part.subparts[0].id; // Error
|
||||
>part.subparts[0].id = part.subparts[0].id : number
|
||||
>part.subparts[0].id : any
|
||||
>part.subparts[0] : DeepReadonlyObject<Part>
|
||||
>part.subparts : DeepReadonlyArray<Part>
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>subparts : DeepReadonlyArray<Part>
|
||||
>0 : 0
|
||||
>id : any
|
||||
>part.subparts[0].id : number
|
||||
>part.subparts[0] : DeepReadonlyObject<Part>
|
||||
>part.subparts : DeepReadonlyArray<Part>
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>subparts : DeepReadonlyArray<Part>
|
||||
>0 : 0
|
||||
>id : number
|
||||
|
||||
part.updatePart("hello"); // Error
|
||||
>part.updatePart("hello") : any
|
||||
>part.updatePart : any
|
||||
>part : DeepReadonlyObject<Part>
|
||||
>updatePart : any
|
||||
>"hello" : "hello"
|
||||
}
|
||||
|
||||
type ZeroOf<T extends number | string | boolean> = T extends number ? 0 : T extends string ? "" : false;
|
||||
>ZeroOf : ZeroOf<T>
|
||||
>T : T
|
||||
>T : T
|
||||
>T : T
|
||||
>false : false
|
||||
|
||||
function zeroOf<T extends number | string | boolean>(value: T) {
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>T : T
|
||||
>value : T
|
||||
>T : T
|
||||
|
||||
return <ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
|
||||
><ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false) : ZeroOf<T>
|
||||
>ZeroOf : ZeroOf<T>
|
||||
>T : T
|
||||
>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false) : false | 0 | ""
|
||||
>typeof value === "number" ? 0 : typeof value === "string" ? "" : false : false | 0 | ""
|
||||
>typeof value === "number" : boolean
|
||||
>typeof value : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
||||
>value : T
|
||||
>"number" : "number"
|
||||
>0 : 0
|
||||
>typeof value === "string" ? "" : false : false | ""
|
||||
>typeof value === "string" : boolean
|
||||
>typeof value : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
||||
>value : T
|
||||
>"string" : "string"
|
||||
>"" : ""
|
||||
>false : false
|
||||
}
|
||||
|
||||
function f20<T extends string>(n: number, b: boolean, x: number | boolean, y: T) {
|
||||
>f20 : <T extends string>(n: number, b: boolean, x: number | boolean, y: T) => void
|
||||
>T : T
|
||||
>n : number
|
||||
>b : boolean
|
||||
>x : number | boolean
|
||||
>y : T
|
||||
>T : T
|
||||
|
||||
zeroOf(5); // 0
|
||||
>zeroOf(5) : 0
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>5 : 5
|
||||
|
||||
zeroOf("hello"); // ""
|
||||
>zeroOf("hello") : ""
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>"hello" : "hello"
|
||||
|
||||
zeroOf(true); // false
|
||||
>zeroOf(true) : false
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>true : true
|
||||
|
||||
zeroOf(n); // 0
|
||||
>zeroOf(n) : 0
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>n : number
|
||||
|
||||
zeroOf(b); // False
|
||||
>zeroOf(b) : false
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>b : boolean
|
||||
|
||||
zeroOf(x); // 0 | false
|
||||
>zeroOf(x) : false | 0
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>x : number | boolean
|
||||
|
||||
zeroOf(y); // ZeroOf<T>
|
||||
>zeroOf(y) : ZeroOf<T>
|
||||
>zeroOf : <T extends string | number | boolean>(value: T) => ZeroOf<T>
|
||||
>y : T
|
||||
}
|
||||
|
||||
function f21<T extends number | string>(x: T, y: ZeroOf<T>) {
|
||||
>f21 : <T extends string | number>(x: T, y: ZeroOf<T>) => void
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>y : ZeroOf<T>
|
||||
>ZeroOf : ZeroOf<T>
|
||||
>T : T
|
||||
|
||||
let z1: number | string = y;
|
||||
>z1 : string | number
|
||||
>y : ZeroOf<T>
|
||||
|
||||
let z2: 0 | "" = y;
|
||||
>z2 : "" | 0
|
||||
>y : ZeroOf<T>
|
||||
|
||||
x = y; // Error
|
||||
>x = y : ZeroOf<T>
|
||||
>x : T
|
||||
>y : ZeroOf<T>
|
||||
|
||||
y = x; // Error
|
||||
>y = x : T
|
||||
>y : ZeroOf<T>
|
||||
>x : T
|
||||
}
|
||||
|
||||
type Extends<T, U> = T extends U ? true : false;
|
||||
>Extends : Extends<T, U>
|
||||
>T : T
|
||||
>U : U
|
||||
>T : T
|
||||
>U : U
|
||||
>true : true
|
||||
>false : false
|
||||
|
||||
type If<C extends boolean, T, F> = C extends true ? T : F;
|
||||
>If : If<C, T, F>
|
||||
>C : C
|
||||
>T : T
|
||||
>F : F
|
||||
>C : C
|
||||
>true : true
|
||||
>T : T
|
||||
>F : F
|
||||
|
||||
type Not<C extends boolean> = If<C, false, true>;
|
||||
>Not : If<C, false, true>
|
||||
>C : C
|
||||
>If : If<C, T, F>
|
||||
>C : C
|
||||
>false : false
|
||||
>true : true
|
||||
|
||||
type And<A extends boolean, B extends boolean> = If<A, B, false>;
|
||||
>And : If<A, B, false>
|
||||
>A : A
|
||||
>B : B
|
||||
>If : If<C, T, F>
|
||||
>A : A
|
||||
>B : B
|
||||
>false : false
|
||||
|
||||
type Or<A extends boolean, B extends boolean> = If<A, true, B>;
|
||||
>Or : If<A, true, B>
|
||||
>A : A
|
||||
>B : B
|
||||
>If : If<C, T, F>
|
||||
>A : A
|
||||
>true : true
|
||||
>B : B
|
||||
|
||||
type isString<T> = Extends<T, string>;
|
||||
>isString : Extends<T, string>
|
||||
>T : T
|
||||
>Extends : Extends<T, U>
|
||||
>T : T
|
||||
|
||||
type Q1 = isString<number>; // false
|
||||
>Q1 : false
|
||||
>isString : Extends<T, string>
|
||||
|
||||
type Q2 = isString<"abc">; // true
|
||||
>Q2 : true
|
||||
>isString : Extends<T, string>
|
||||
|
||||
type Q3 = isString<any>; // boolean
|
||||
>Q3 : boolean
|
||||
>isString : Extends<T, string>
|
||||
|
||||
type Q4 = isString<never>; // boolean
|
||||
>Q4 : boolean
|
||||
>isString : Extends<T, string>
|
||||
|
||||
type N1 = Not<false>; // true
|
||||
>N1 : true
|
||||
>Not : If<C, false, true>
|
||||
>false : false
|
||||
|
||||
type N2 = Not<true>; // false
|
||||
>N2 : false
|
||||
>Not : If<C, false, true>
|
||||
>true : true
|
||||
|
||||
type N3 = Not<boolean>; // boolean
|
||||
>N3 : boolean
|
||||
>Not : If<C, false, true>
|
||||
|
||||
type A1 = And<false, false>; // false
|
||||
>A1 : false
|
||||
>And : If<A, B, false>
|
||||
>false : false
|
||||
>false : false
|
||||
|
||||
type A2 = And<false, true>; // false
|
||||
>A2 : false
|
||||
>And : If<A, B, false>
|
||||
>false : false
|
||||
>true : true
|
||||
|
||||
type A3 = And<true, false>; // false
|
||||
>A3 : false
|
||||
>And : If<A, B, false>
|
||||
>true : true
|
||||
>false : false
|
||||
|
||||
type A4 = And<true, true>; // true
|
||||
>A4 : true
|
||||
>And : If<A, B, false>
|
||||
>true : true
|
||||
>true : true
|
||||
|
||||
type A5 = And<boolean, false>; // false
|
||||
>A5 : false
|
||||
>And : If<A, B, false>
|
||||
>false : false
|
||||
|
||||
type A6 = And<false, boolean>; // false
|
||||
>A6 : false
|
||||
>And : If<A, B, false>
|
||||
>false : false
|
||||
|
||||
type A7 = And<boolean, true>; // boolean
|
||||
>A7 : boolean
|
||||
>And : If<A, B, false>
|
||||
>true : true
|
||||
|
||||
type A8 = And<true, boolean>; // boolean
|
||||
>A8 : boolean
|
||||
>And : If<A, B, false>
|
||||
>true : true
|
||||
|
||||
type A9 = And<boolean, boolean>; // boolean
|
||||
>A9 : boolean
|
||||
>And : If<A, B, false>
|
||||
|
||||
type O1 = Or<false, false>; // false
|
||||
>O1 : false
|
||||
>Or : If<A, true, B>
|
||||
>false : false
|
||||
>false : false
|
||||
|
||||
type O2 = Or<false, true>; // true
|
||||
>O2 : true
|
||||
>Or : If<A, true, B>
|
||||
>false : false
|
||||
>true : true
|
||||
|
||||
type O3 = Or<true, false>; // true
|
||||
>O3 : true
|
||||
>Or : If<A, true, B>
|
||||
>true : true
|
||||
>false : false
|
||||
|
||||
type O4 = Or<true, true>; // true
|
||||
>O4 : true
|
||||
>Or : If<A, true, B>
|
||||
>true : true
|
||||
>true : true
|
||||
|
||||
type O5 = Or<boolean, false>; // boolean
|
||||
>O5 : boolean
|
||||
>Or : If<A, true, B>
|
||||
>false : false
|
||||
|
||||
type O6 = Or<false, boolean>; // boolean
|
||||
>O6 : boolean
|
||||
>Or : If<A, true, B>
|
||||
>false : false
|
||||
|
||||
type O7 = Or<boolean, true>; // true
|
||||
>O7 : true
|
||||
>Or : If<A, true, B>
|
||||
>true : true
|
||||
|
||||
type O8 = Or<true, boolean>; // true
|
||||
>O8 : true
|
||||
>Or : If<A, true, B>
|
||||
>true : true
|
||||
|
||||
type O9 = Or<boolean, boolean>; // boolean
|
||||
>O9 : boolean
|
||||
>Or : If<A, true, B>
|
||||
|
||||
@@ -97,7 +97,7 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
|
||||
if (typeof arg == "object") {
|
||||
>typeof arg == "object" : boolean
|
||||
>typeof arg : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
||||
>arg : keyof S | (object & { [K in keyof S]?: boolean; })
|
||||
>arg : object & { [K in keyof S]?: boolean; }
|
||||
>"object" : "object"
|
||||
|
||||
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
|
||||
@@ -107,7 +107,7 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
|
||||
>Object.keys : (o: {}) => string[]
|
||||
>Object : ObjectConstructor
|
||||
>keys : (o: {}) => string[]
|
||||
>arg : keyof S | (object & { [K in keyof S]?: boolean; })
|
||||
>arg : object & { [K in keyof S]?: boolean; }
|
||||
>reduce : { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string; <U>(callbackfn: (previousValue: U, currentValue: string, currentIndex: number, array: string[]) => U, initialValue: U): U; }
|
||||
>ClassNameObject : No type information available!
|
||||
>(obj: ClassNameObject, key: keyof S) => { const exportedClassName = styles[key]; obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; return obj; } : (obj: any, key: keyof S) => any
|
||||
@@ -130,7 +130,7 @@ export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNam
|
||||
>(arg as ClassNameMap<S>)[key] : { [K in keyof S]?: boolean; }[keyof S]
|
||||
>(arg as ClassNameMap<S>) : { [K in keyof S]?: boolean; }
|
||||
>arg as ClassNameMap<S> : { [K in keyof S]?: boolean; }
|
||||
>arg : keyof S | (object & { [K in keyof S]?: boolean; })
|
||||
>arg : object & { [K in keyof S]?: boolean; }
|
||||
>ClassNameMap : { [K in keyof S]?: boolean; }
|
||||
>S : S
|
||||
>key : keyof S
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
// @strict: true
|
||||
// @declaration: true
|
||||
|
||||
type Diff<T, U> = T extends U ? never : T;
|
||||
type Filter<T, U> = T extends U ? T : never;
|
||||
type NonNullable<T> = Diff<T, null | undefined>;
|
||||
|
||||
type T00 = Diff<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d"
|
||||
type T01 = Filter<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c"
|
||||
|
||||
type T02 = Diff<string | number | (() => void), Function>; // string | number
|
||||
type T03 = Filter<string | number | (() => void), Function>; // () => void
|
||||
|
||||
type T04 = NonNullable<string | number | undefined>; // string | number
|
||||
type T05 = NonNullable<(() => string) | string[] | null | undefined>; // (() => string) | string[]
|
||||
|
||||
function f1<T>(x: T, y: NonNullable<T>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
function f2<T extends string | undefined>(x: T, y: NonNullable<T>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
let s1: string = x; // Error
|
||||
let s2: string = y;
|
||||
}
|
||||
|
||||
function f3<T>(x: Partial<T>[keyof T], y: NonNullable<Partial<T>[keyof T]>) {
|
||||
x = y;
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: boolean };
|
||||
|
||||
type T10 = Diff<Options, { k: "a" | "b" }>; // { k: "c", c: boolean }
|
||||
type T11 = Filter<Options, { k: "a" | "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T12 = Diff<Options, { k: "a" } | { k: "b" }>; // { k: "c", c: boolean }
|
||||
type T13 = Filter<Options, { k: "a" } | { k: "b" }>; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type T14 = Diff<Options, { q: "a" }>; // Options
|
||||
type T15 = Filter<Options, { q: "a" }>; // never
|
||||
|
||||
declare function f4<T extends Options, K extends string>(p: K): Filter<T, { k: K }>;
|
||||
let x0 = f4("a"); // { k: "a", a: number }
|
||||
|
||||
type OptionsOfKind<K extends Options["k"]> = Filter<Options, { k: K }>;
|
||||
|
||||
type T16 = OptionsOfKind<"a" | "b">; // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type Select<T, K extends keyof T, V extends T[K]> = Filter<T, { [P in K]: V }>;
|
||||
|
||||
type T17 = Select<Options, "k", "a" | "b">; // // { k: "a", a: number } | { k: "b", b: string }
|
||||
|
||||
type TypeName<T> =
|
||||
T extends string ? "string" :
|
||||
T extends number ? "number" :
|
||||
T extends boolean ? "boolean" :
|
||||
T extends undefined ? "undefined" :
|
||||
T extends Function ? "function" :
|
||||
"object";
|
||||
|
||||
type T20 = TypeName<string | (() => void)>; // "string" | "function"
|
||||
type T21 = TypeName<any>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
type T22 = TypeName<never>; // "string" | "number" | "boolean" | "undefined" | "function" | "object"
|
||||
type T23 = TypeName<{}>; // "object"
|
||||
|
||||
type KnockoutObservable<T> = { object: T };
|
||||
type KnockoutObservableArray<T> = { array: T };
|
||||
|
||||
type KnockedOut<T> = T extends any[] ? KnockoutObservableArray<T[number]> : KnockoutObservable<T>;
|
||||
|
||||
type KnockedOutObj<T> = {
|
||||
[P in keyof T]: KnockedOut<T[P]>;
|
||||
}
|
||||
|
||||
interface Item {
|
||||
id: number;
|
||||
name: string;
|
||||
subitems: string[];
|
||||
}
|
||||
|
||||
type KOItem = KnockedOutObj<Item>;
|
||||
|
||||
interface Part {
|
||||
id: number;
|
||||
name: string;
|
||||
subparts: Part[];
|
||||
updatePart(newName: string): void;
|
||||
}
|
||||
|
||||
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
||||
type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
|
||||
|
||||
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
|
||||
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
||||
|
||||
type T30 = FunctionProperties<Part>;
|
||||
type T31 = NonFunctionProperties<Part>;
|
||||
|
||||
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
|
||||
x = y; // Error
|
||||
x = z; // Error
|
||||
y = x;
|
||||
y = z; // Error
|
||||
z = x;
|
||||
z = y; // Error
|
||||
}
|
||||
|
||||
function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
|
||||
x = y;
|
||||
x = z;
|
||||
y = x; // Error
|
||||
y = z; // Error
|
||||
z = x; // Error
|
||||
z = y; // Error
|
||||
}
|
||||
|
||||
type DeepReadonly<T> =
|
||||
T extends any[] ? DeepReadonlyArray<T[number]> :
|
||||
T extends object ? DeepReadonlyObject<T> :
|
||||
T;
|
||||
|
||||
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
|
||||
|
||||
type DeepReadonlyObject<T> = {
|
||||
readonly [P in NonFunctionPropertyNames<T>]: DeepReadonly<T[P]>;
|
||||
};
|
||||
|
||||
function f10(part: DeepReadonly<Part>) {
|
||||
let name: string = part.name;
|
||||
let id: number = part.subparts[0].id;
|
||||
part.id = part.id; // Error
|
||||
part.subparts[0] = part.subparts[0]; // Error
|
||||
part.subparts[0].id = part.subparts[0].id; // Error
|
||||
part.updatePart("hello"); // Error
|
||||
}
|
||||
|
||||
type ZeroOf<T extends number | string | boolean> = T extends number ? 0 : T extends string ? "" : false;
|
||||
|
||||
function zeroOf<T extends number | string | boolean>(value: T) {
|
||||
return <ZeroOf<T>>(typeof value === "number" ? 0 : typeof value === "string" ? "" : false);
|
||||
}
|
||||
|
||||
function f20<T extends string>(n: number, b: boolean, x: number | boolean, y: T) {
|
||||
zeroOf(5); // 0
|
||||
zeroOf("hello"); // ""
|
||||
zeroOf(true); // false
|
||||
zeroOf(n); // 0
|
||||
zeroOf(b); // False
|
||||
zeroOf(x); // 0 | false
|
||||
zeroOf(y); // ZeroOf<T>
|
||||
}
|
||||
|
||||
function f21<T extends number | string>(x: T, y: ZeroOf<T>) {
|
||||
let z1: number | string = y;
|
||||
let z2: 0 | "" = y;
|
||||
x = y; // Error
|
||||
y = x; // Error
|
||||
}
|
||||
|
||||
type Extends<T, U> = T extends U ? true : false;
|
||||
type If<C extends boolean, T, F> = C extends true ? T : F;
|
||||
type Not<C extends boolean> = If<C, false, true>;
|
||||
type And<A extends boolean, B extends boolean> = If<A, B, false>;
|
||||
type Or<A extends boolean, B extends boolean> = If<A, true, B>;
|
||||
|
||||
type isString<T> = Extends<T, string>;
|
||||
|
||||
type Q1 = isString<number>; // false
|
||||
type Q2 = isString<"abc">; // true
|
||||
type Q3 = isString<any>; // boolean
|
||||
type Q4 = isString<never>; // boolean
|
||||
|
||||
type N1 = Not<false>; // true
|
||||
type N2 = Not<true>; // false
|
||||
type N3 = Not<boolean>; // boolean
|
||||
|
||||
type A1 = And<false, false>; // false
|
||||
type A2 = And<false, true>; // false
|
||||
type A3 = And<true, false>; // false
|
||||
type A4 = And<true, true>; // true
|
||||
type A5 = And<boolean, false>; // false
|
||||
type A6 = And<false, boolean>; // false
|
||||
type A7 = And<boolean, true>; // boolean
|
||||
type A8 = And<true, boolean>; // boolean
|
||||
type A9 = And<boolean, boolean>; // boolean
|
||||
|
||||
type O1 = Or<false, false>; // false
|
||||
type O2 = Or<false, true>; // true
|
||||
type O3 = Or<true, false>; // true
|
||||
type O4 = Or<true, true>; // true
|
||||
type O5 = Or<boolean, false>; // boolean
|
||||
type O6 = Or<false, boolean>; // boolean
|
||||
type O7 = Or<boolean, true>; // true
|
||||
type O8 = Or<true, boolean>; // true
|
||||
type O9 = Or<boolean, boolean>; // boolean
|
||||
Reference in New Issue
Block a user