From b95a4307e3c77c4ba40f23790919ef4da06c5cee Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 5 Jun 2019 15:30:55 -0700 Subject: [PATCH 1/2] Experimental implementation of negated (`not T`) types --- src/compiler/checker.ts | 313 +++++++++++-- src/compiler/factory.ts | 4 +- src/compiler/parser.ts | 3 +- src/compiler/scanner.ts | 1 + src/compiler/types.ts | 22 +- src/harness/fourslash.ts | 4 +- src/services/utilities.ts | 1 + .../reference/api/tsserverlibrary.d.ts | 413 ++++++++--------- tests/baselines/reference/api/typescript.d.ts | 413 ++++++++--------- .../assignmentCompatability24.errors.txt | 4 +- .../checkJsxChildrenProperty4.errors.txt | 8 +- ...heckJsxSubtleSkipContextSensitiveBug.types | 8 +- ...nalNoInfiniteInstantiationDepth.errors.txt | 164 ++++--- .../reference/conditionalTypes1.errors.txt | 22 +- .../reference/conditionalTypes1.types | 64 +-- .../reference/conditionalTypes2.errors.txt | 8 +- .../reference/conditionalTypes2.types | 8 +- ...lWithGenericSignatureArguments3.errors.txt | 16 +- .../genericRestParameters1.errors.txt | 7 +- .../reference/genericRestParameters1.types | 2 +- tests/baselines/reference/inferTypes1.types | 18 +- .../reference/infiniteConstraints.errors.txt | 5 +- .../instantiateContextualTypes.types | 4 +- .../intersectionWithUnionConstraint.types | 12 +- .../reference/mappedTypesArraysTuples.types | 16 +- .../negatedFreshTreatedAsClosedSet.errors.txt | 21 + .../negatedFreshTreatedAsClosedSet.js | 17 + .../negatedFreshTreatedAsClosedSet.symbols | 39 ++ .../negatedFreshTreatedAsClosedSet.types | 42 ++ ...pedTypeDisablesExcessProperties.errors.txt | 38 ++ ...tedInMappedTypeDisablesExcessProperties.js | 42 ++ ...MappedTypeDisablesExcessProperties.symbols | 52 +++ ...InMappedTypeDisablesExcessProperties.types | 56 +++ .../baselines/reference/negatedPromiseRepr.js | 62 +++ .../reference/negatedPromiseRepr.symbols | 281 ++++++++++++ .../reference/negatedPromiseRepr.types | 180 ++++++++ .../negatedRepresentativeExamples.errors.txt | 61 +++ .../negatedRepresentativeExamples.js | 53 +++ .../negatedRepresentativeExamples.symbols | 110 +++++ .../negatedRepresentativeExamples.types | 129 ++++++ ...edTypeAppliesToFalseBranchOfConditional.js | 10 + ...eAppliesToFalseBranchOfConditional.symbols | 17 + ...ypeAppliesToFalseBranchOfConditional.types | 11 + .../reference/negatedTypes.errors.txt | 309 +++++++++++++ tests/baselines/reference/negatedTypes.js | 193 ++++++++ .../baselines/reference/negatedTypes.symbols | 364 +++++++++++++++ tests/baselines/reference/negatedTypes.types | 432 ++++++++++++++++++ .../reference/negatedTypesControlFlow.js | 33 ++ .../reference/negatedTypesControlFlow.symbols | 72 +++ .../reference/negatedTypesControlFlow.types | 72 +++ .../negatedTypesSimplifyInIntersections.js | 6 + ...egatedTypesSimplifyInIntersections.symbols | 7 + .../negatedTypesSimplifyInIntersections.types | 8 + ...structorFixesInferencesAppropriately.types | 10 +- ...ferredInferenceAllowsAssignment.errors.txt | 164 ++++--- .../types/conditional/conditionalTypes1.ts | 1 - .../negated/negatedFreshTreatedAsClosedSet.ts | 10 + ...tedInMappedTypeDisablesExcessProperties.ts | 24 + .../types/negated/negatedPromiseRepr.ts | 52 +++ .../negated/negatedRepresentativeExamples.ts | 33 ++ ...edTypeAppliesToFalseBranchOfConditional.ts | 5 + .../conformance/types/negated/negatedTypes.ts | 109 +++++ .../types/negated/negatedTypesControlFlow.ts | 19 + .../negatedTypesSimplifyInIntersections.ts | 2 + 64 files changed, 4002 insertions(+), 684 deletions(-) create mode 100644 tests/baselines/reference/negatedFreshTreatedAsClosedSet.errors.txt create mode 100644 tests/baselines/reference/negatedFreshTreatedAsClosedSet.js create mode 100644 tests/baselines/reference/negatedFreshTreatedAsClosedSet.symbols create mode 100644 tests/baselines/reference/negatedFreshTreatedAsClosedSet.types create mode 100644 tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.errors.txt create mode 100644 tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.js create mode 100644 tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.symbols create mode 100644 tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.types create mode 100644 tests/baselines/reference/negatedPromiseRepr.js create mode 100644 tests/baselines/reference/negatedPromiseRepr.symbols create mode 100644 tests/baselines/reference/negatedPromiseRepr.types create mode 100644 tests/baselines/reference/negatedRepresentativeExamples.errors.txt create mode 100644 tests/baselines/reference/negatedRepresentativeExamples.js create mode 100644 tests/baselines/reference/negatedRepresentativeExamples.symbols create mode 100644 tests/baselines/reference/negatedRepresentativeExamples.types create mode 100644 tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.js create mode 100644 tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.symbols create mode 100644 tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.types create mode 100644 tests/baselines/reference/negatedTypes.errors.txt create mode 100644 tests/baselines/reference/negatedTypes.js create mode 100644 tests/baselines/reference/negatedTypes.symbols create mode 100644 tests/baselines/reference/negatedTypes.types create mode 100644 tests/baselines/reference/negatedTypesControlFlow.js create mode 100644 tests/baselines/reference/negatedTypesControlFlow.symbols create mode 100644 tests/baselines/reference/negatedTypesControlFlow.types create mode 100644 tests/baselines/reference/negatedTypesSimplifyInIntersections.js create mode 100644 tests/baselines/reference/negatedTypesSimplifyInIntersections.symbols create mode 100644 tests/baselines/reference/negatedTypesSimplifyInIntersections.types create mode 100644 tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts create mode 100644 tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts create mode 100644 tests/cases/conformance/types/negated/negatedPromiseRepr.ts create mode 100644 tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts create mode 100644 tests/cases/conformance/types/negated/negatedTypeAppliesToFalseBranchOfConditional.ts create mode 100644 tests/cases/conformance/types/negated/negatedTypes.ts create mode 100644 tests/cases/conformance/types/negated/negatedTypesControlFlow.ts create mode 100644 tests/cases/conformance/types/negated/negatedTypesSimplifyInIntersections.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf614ee201395..21d4bfb7e039d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -395,6 +395,7 @@ namespace ts { const tupleTypes = createMap(); const unionTypes = createMap(); + const negatedTypes = createMap(); const intersectionTypes = createMap(); const literalTypes = createMap(); const indexedAccessTypes = createMap(); @@ -3579,6 +3580,10 @@ namespace ts { context.approximateLength += 4; return createThis(); } + if (type.flags & TypeFlags.Negated) { + context.approximateLength += 4; + return createTypeOperatorNode(SyntaxKind.NotKeyword, typeToTypeNodeHelper((type as NegatedType).type, context)); + } const objectFlags = getObjectFlags(type); @@ -5855,7 +5860,8 @@ namespace ts { return type; } } - const type = createObjectType(ObjectFlags.Anonymous, symbol); + const isClosed = isFunctionExpression(declaration) || isArrowFunction(declaration); + const type = createObjectType(ObjectFlags.Anonymous | (isClosed ? ObjectFlags.ObjectLiteral : 0), symbol); if (symbol.flags & SymbolFlags.Class) { const baseTypeVariable = getBaseTypeVariableOfClass(symbol); return baseTypeVariable ? getIntersectionType([type, baseTypeVariable]) : type; @@ -7704,7 +7710,7 @@ namespace ts { // just `any`. This result is _usually_ unwanted - so instead here we elide an `any` branch from the constraint type, // in effect treating `any` like `never` rather than `unknown` in this location. const trueConstraint = getInferredTrueTypeFromConditionalType(type); - const falseConstraint = getFalseTypeFromConditionalType(type); + const falseConstraint = getInferredFalseTypeFromConditionalType(type); type.resolvedDefaultConstraint = isTypeAny(trueConstraint) ? falseConstraint : isTypeAny(falseConstraint) ? trueConstraint : getUnionType([trueConstraint, falseConstraint]); } return type.resolvedDefaultConstraint; @@ -7748,7 +7754,7 @@ namespace ts { let constraints: Type[] | undefined; let hasDisjointDomainType = false; for (const t of type.types) { - if (t.flags & TypeFlags.Instantiable) { + if (t.flags & TypeFlags.Instantiable && !(t.flags & TypeFlags.Negated)) { // We keep following constraints as long as we have an instantiable type that is known // not to be circular or infinite (hence we stop on index access types). let constraint = getConstraintOfType(t); @@ -7759,7 +7765,7 @@ namespace ts { constraints = append(constraints, constraint); } } - else if (t.flags & TypeFlags.DisjointDomains) { + else if (t.flags & TypeFlags.DisjointDomains || t.flags & TypeFlags.Negated) { hasDisjointDomainType = true; } } @@ -7770,7 +7776,7 @@ namespace ts { // We add any types belong to one of the disjoint domains because they might cause the final // intersection operation to reduce the union constraints. for (const t of type.types) { - if (t.flags & TypeFlags.DisjointDomains) { + if (t.flags & TypeFlags.DisjointDomains || t.flags & TypeFlags.Negated) { constraints = append(constraints, t); } } @@ -9118,10 +9124,10 @@ namespace ts { let constraints: Type[] | undefined; while (node && !isStatement(node) && node.kind !== SyntaxKind.JSDocComment) { const parent = node.parent; - if (parent.kind === SyntaxKind.ConditionalType && node === (parent).trueType) { + if (parent.kind === SyntaxKind.ConditionalType && (node === (parent).trueType || node === (parent).falseType)) { const constraint = getImpliedConstraint(typeVariable, (parent).checkType, (parent).extendsType); if (constraint) { - constraints = append(constraints, constraint); + constraints = append(constraints, node === (parent).trueType ? constraint : getNegatedType(constraint)); } } node = parent; @@ -9857,6 +9863,59 @@ namespace ts { return true; } + function checkForUnsatisfiedNegatedType(typeSet: Type[]) { + const nonNegatedSet = filter(typeSet, t => !(t.flags & TypeFlags.Negated)); + if (!length(nonNegatedSet)) { + return false; + } + const negatedBounds = getUnionType(map(filter(typeSet, t => !!(t.flags & TypeFlags.Negated)), t => (t as NegatedType).type)); + for (const nonNegatedType of nonNegatedSet) { + if (isTypeSubtypeOf(nonNegatedType, negatedBounds)) { + return true; + } + } + return false; + } + + function removeNegatedSubtypes(types: Type[]) { + if (types.length === 0) { + return; + } + let i = types.length; + const nonNegatedBounds = filter(types, t => !(t.flags & TypeFlags.Negated)); + if (!length(nonNegatedBounds)) { + return; + } + const nonNegativePart = getIntersectionType(nonNegatedBounds); + while (i > 0) { + i--; + if (types[i].flags & TypeFlags.Negated) { + if (isTypeSubtypeOf(nonNegativePart, types[i])) { + orderedRemoveItemAt(types, i); + } + } + } + } + + function checkForUnsatisfiedTypeVariableConstraint(typeSet: Type[]) { + const nonVariablePart = filter(typeSet, t => !(t.flags & TypeFlags.TypeVariable)); + if (!length(nonVariablePart)) { + return false; + } + const variables = filter(typeSet, t => !!(t.flags & TypeFlags.TypeVariable)); + for (const toCheck of nonVariablePart) { + for (const variable of variables) { + const constraint = getConstraintOfType(variable); + if (constraint && (constraint.flags & TypeFlags.Primitive || constraint.flags && TypeFlags.Union && (constraint as UnionType).objectFlags & ObjectFlags.PrimitiveUnion)) { + if (isIntersectionEmpty(toCheck, constraint)) { + return true; + } + } + } + } + return false; + } + function createIntersectionType(types: Type[], aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray) { const result = createType(TypeFlags.Intersection); result.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ TypeFlags.Nullable); @@ -9922,34 +9981,47 @@ namespace ts { const id = getTypeListId(typeSet); let result = intersectionTypes.get(id); if (!result) { - if (includes & TypeFlags.Union) { - if (intersectUnionsOfPrimitiveTypes(typeSet)) { - // When the intersection creates a reduced set (which might mean that *all* union types have - // disappeared), we restart the operation to get a new set of combined flags. Once we have - // reduced we'll never reduce again, so this occurs at most once. - result = getIntersectionType(typeSet, aliasSymbol, aliasTypeArguments); - } - else { - // We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of - // the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain. - // If the estimated size of the resulting union type exceeds 100000 constituents, report an error. - const size = reduceLeft(typeSet, (n, t) => n * (t.flags & TypeFlags.Union ? (t).types.length : 1), 1); - if (size >= 100000) { - error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent); - return errorType; - } - const unionIndex = findIndex(typeSet, t => (t.flags & TypeFlags.Union) !== 0); - const unionType = typeSet[unionIndex]; - result = getUnionType(map(unionType.types, t => getIntersectionType(replaceElement(typeSet, unionIndex, t))), - UnionReduction.Literal, aliasSymbol, aliasTypeArguments); - } + result = getIntersectionTypeWorker(includes, typeSet, aliasSymbol, aliasTypeArguments); + intersectionTypes.set(id, result); + } + return result; + } + + function getIntersectionTypeWorker(includes: TypeFlags, typeSet: Type[], aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray) { + if (includes & TypeFlags.Union) { + if (intersectUnionsOfPrimitiveTypes(typeSet)) { + // When the intersection creates a reduced set (which might mean that *all* union types have + // disappeared), we restart the operation to get a new set of combined flags. Once we have + // reduced we'll never reduce again, so this occurs at most once. + return getIntersectionType(typeSet, aliasSymbol, aliasTypeArguments); } else { - result = createIntersectionType(typeSet, aliasSymbol, aliasTypeArguments); + // We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of + // the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain. + // If the estimated size of the resulting union type exceeds 100000 constituents, report an error. + const size = reduceLeft(typeSet, (n, t) => n * (t.flags & TypeFlags.Union ? (t).types.length : 1), 1); + if (size >= 100000) { + error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent); + return errorType; + } + const unionIndex = findIndex(typeSet, t => (t.flags & TypeFlags.Union) !== 0); + const unionType = typeSet[unionIndex]; + return getUnionType(map(unionType.types, t => getIntersectionType(replaceElement(typeSet, unionIndex, t))), + UnionReduction.Literal, aliasSymbol, aliasTypeArguments); } - intersectionTypes.set(id, result); } - return result; + if (includes & TypeFlags.TypeVariable) { + if (checkForUnsatisfiedTypeVariableConstraint(typeSet)) { + return neverType; + } + } + if (includes & TypeFlags.Negated) { + if (checkForUnsatisfiedNegatedType(typeSet)) { + return neverType; + } + removeNegatedSubtypes(typeSet); + } + return createIntersectionType(typeSet, aliasSymbol, aliasTypeArguments); } function getTypeFromIntersectionTypeNode(node: IntersectionTypeNode): Type { @@ -10015,9 +10087,35 @@ namespace ts { return numberIndexInfo !== enumNumberIndexInfo ? numberIndexInfo : undefined; } + function getIndexTypeForNegatedType(type: NegatedType, stringsOnly: boolean, noIndexSignatures: boolean | undefined) { + // `keyof not A` is difficult to reason about - `not A` could have any number of keys on its component types + // However there are certain cases, like `keyof not { x: unknown }` where you can safely conclude that the keyof + // result should be `not "x" & (string | number | symbol)`, because the type negated effectively forbids the key + // eg, `not {[x: string]: any}` should produce `not string & (string | number | symbol)` or simply `number | symbol` + // but take `keyof not {x: any, y: string}` - we can't conclude anything about the keys of the negation here - `{x: 12}` + // is in the negation because it's missing a `y` key, so the `keyof` cannot include `x` + // likewise considering `keyof not {x: any, y: any}`, we can't still conclude that `not "x"` is a key because `{x: 12}` + // is _still_ in `not {x: any, y: any}`. + // This indicates that we only time we can produce a negated result from a `keyof` is when we are taking a `keyof` a + // type with a _single_ field of type `any` or `unknown` + // We can't really do any better, since `keyof` is effectively capturing a lower bound, while most of our type logic reasons + // over upper bounds + // When we have more than a single known-any property, a `keyof not Whatever` must therefore be `never`, as, much like `keyof {}`, + // we have no knowledge of the structure of the types in the domain. + const rawUnnegated = getIndexType(type.type, stringsOnly, noIndexSignatures); + if (rawUnnegated.flags & TypeFlags.Index) { + return getIndexTypeForGenericType(type, stringsOnly); + } + if (!(rawUnnegated.flags & TypeFlags.Union) && (getIndexedAccessType(type.type, rawUnnegated).flags & TypeFlags.AnyOrUnknown)) { + return intersectTypes(getNegatedType(rawUnnegated), keyofConstraintType); + } + return neverType; + } + function getIndexType(type: Type, stringsOnly = keyofStringsOnly, noIndexSignatures?: boolean): Type { return type.flags & TypeFlags.Union ? getIntersectionType(map((type).types, t => getIndexType(t, stringsOnly, noIndexSignatures))) : type.flags & TypeFlags.Intersection ? getUnionType(map((type).types, t => getIndexType(t, stringsOnly, noIndexSignatures))) : + type.flags & TypeFlags.Negated ? getIndexTypeForNegatedType(type as NegatedType, stringsOnly, noIndexSignatures) : maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive) ? getIndexTypeForGenericType(type, stringsOnly) : getObjectFlags(type) & ObjectFlags.Mapped ? filterType(getConstraintTypeFromMappedType(type), t => !(noIndexSignatures && t.flags & (TypeFlags.Any | TypeFlags.String))) : type === wildcardType ? wildcardType : @@ -10049,6 +10147,9 @@ namespace ts { case SyntaxKind.KeyOfKeyword: links.resolvedType = getIndexType(getTypeFromTypeNode(node.type)); break; + case SyntaxKind.NotKeyword: + links.resolvedType = getNegatedType(getTypeFromTypeNode(node.type)); + break; case SyntaxKind.UniqueKeyword: links.resolvedType = node.type.kind === SyntaxKind.SymbolKeyword ? getESSymbolLikeTypeForNode(walkUpParenthesizedTypes(node.parent)) @@ -10091,6 +10192,9 @@ namespace ts { if (type.flags & TypeFlags.Intersection) { return some((type as IntersectionType).types, isJSLiteralType); } + if (type.flags & TypeFlags.Negated) { + return false; + } if (type.flags & TypeFlags.Instantiable) { return isJSLiteralType(getResolvedBaseConstraint(type)); } @@ -10264,11 +10368,11 @@ namespace ts { } function isGenericObjectType(type: Type): boolean { - return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.GenericMappedType); + return maybeTypeOfKindUnwrapNegations(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.GenericMappedType); } function isGenericIndexType(type: Type): boolean { - return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index); + return maybeTypeOfKindUnwrapNegations(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index); } function isThisTypeParameter(type: Type): boolean { @@ -10320,7 +10424,7 @@ namespace ts { return type[cache] = distributedOverIndex; } // Only do the inner distributions if the index can no longer be instantiated to cause index distribution again - if (!(indexType.flags & TypeFlags.Instantiable)) { + if (!(indexType.flags & (TypeFlags.Instantiable & ~TypeFlags.Negated))) { // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] @@ -10485,10 +10589,12 @@ namespace ts { if (checkType === wildcardType || extendsType === wildcardType) { return wildcardType; } - const checkTypeInstantiable = maybeTypeOfKind(checkType, TypeFlags.Instantiable | TypeFlags.GenericMappedType); + const checkTypeInstantiable = maybeTypeOfKindUnwrapNegations(checkType, TypeFlags.Instantiable | TypeFlags.GenericMappedType); let combinedMapper: TypeMapper | undefined; + let falseCombinedMapper: TypeMapper | undefined; if (root.inferTypeParameters) { const context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, InferenceFlags.None); + falseCombinedMapper = combineTypeMappers(mapper, cloneInferenceContext(context).mapper); if (!checkTypeInstantiable) { // We don't want inferences from constraints as they may cause us to eagerly resolve the // conditional type instead of deferring resolution. Also, we always want strict function @@ -10500,20 +10606,20 @@ namespace ts { // Instantiate the extends type including inferences for 'infer T' type parameters const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType; // We attempt to resolve the conditional type only when the check and extends types are non-generic - if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, TypeFlags.Instantiable | TypeFlags.GenericMappedType)) { + if (!checkTypeInstantiable && !maybeTypeOfKindUnwrapNegations(inferredExtendsType, TypeFlags.Instantiable | TypeFlags.GenericMappedType)) { if (inferredExtendsType.flags & TypeFlags.AnyOrUnknown) { return instantiateType(root.trueType, combinedMapper || mapper); } // Return union of trueType and falseType for 'any' since it matches anything if (checkType.flags & TypeFlags.Any) { - return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, mapper)]); + return getUnionType([instantiateType(root.trueType, combinedMapper || mapper), instantiateType(root.falseType, falseCombinedMapper || mapper)]); } // Return falseType for a definitely false extends check. We check an instantiations of the two // types with type parameters mapped to the wildcard type, the most permissive instantiations // possible (the wildcard type is assignable to and from all types). If those are not related, // then no instantiations will be and we can just return the false branch type. if (!isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType))) { - return instantiateType(root.falseType, mapper); + return instantiateType(root.falseType, falseCombinedMapper || mapper); } // Return trueType for a definitely true extends check. We check instantiations of the two // types with type parameters mapped to their restrictive form, i.e. a form of the type parameter @@ -10532,6 +10638,7 @@ namespace ts { result.extendsType = extendsType; result.mapper = mapper; result.combinedMapper = combinedMapper; + result.falseCombinedMapper = falseCombinedMapper; result.aliasSymbol = root.aliasSymbol; result.aliasTypeArguments = instantiateTypes(root.aliasTypeArguments, mapper!); // TODO: GH#18217 return result; @@ -10549,6 +10656,10 @@ namespace ts { return type.resolvedInferredTrueType || (type.resolvedInferredTrueType = type.combinedMapper ? instantiateType(type.root.trueType, type.combinedMapper) : getTrueTypeFromConditionalType(type)); } + function getInferredFalseTypeFromConditionalType(type: ConditionalType) { + return type.resolvedInferredFalseType || (type.resolvedInferredFalseType = type.falseCombinedMapper ? instantiateType(type.root.falseType, type.falseCombinedMapper) : getFalseTypeFromConditionalType(type)); + } + function getInferTypeParameters(node: ConditionalTypeNode): TypeParameter[] | undefined { let result: TypeParameter[] | undefined; if (node.locals) { @@ -10599,6 +10710,36 @@ namespace ts { return links.resolvedType; } + function getNegatedType(type: Type): Type { + if (type.flags & TypeFlags.Negated) { + return (type as NegatedType).type; + } + if (type.flags & TypeFlags.Union) { + return getIntersectionType(map((type as UnionType).types, getNegatedType)); + } + if (type.flags & TypeFlags.Intersection) { + return getUnionType(map((type as IntersectionType).types, getNegatedType)); + } + if (type.flags & TypeFlags.Any) { + return type; + } + if (type.flags & TypeFlags.Unknown) { + return neverType; + } + if (type.flags & TypeFlags.Never) { + return unknownType; + } + const inputId = getTypeId(type); + const existing = negatedTypes.get("" + inputId); + if (existing) { + return existing; + } + const newNegated = createType(TypeFlags.Negated) as NegatedType; + newNegated.type = type; + negatedTypes.set("" + inputId, newNegated); + return newNegated; + } + function getIdentifierChain(node: EntityName): Identifier[] { if (isIdentifier(node)) { return [node]; @@ -11170,7 +11311,7 @@ namespace ts { function instantiateSymbol(symbol: Symbol, mapper: TypeMapper): Symbol { const links = getSymbolLinks(symbol); - if (links.type && !maybeTypeOfKind(links.type, TypeFlags.Object | TypeFlags.Instantiable)) { + if (links.type && !maybeTypeOfKindUnwrapNegations(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; @@ -11469,6 +11610,9 @@ namespace ts { if (flags & TypeFlags.Conditional) { return getConditionalTypeInstantiation(type, combineTypeMappers((type).mapper, mapper)); } + if (flags & TypeFlags.Negated) { + return getNegatedType(instantiateType((type as NegatedType).type, mapper)); + } if (flags & TypeFlags.Substitution) { const maybeVariable = instantiateType((type).typeVariable, mapper); if (maybeVariable.flags & TypeFlags.TypeVariable) { @@ -11479,7 +11623,7 @@ namespace ts { if (sub.flags & TypeFlags.AnyOrUnknown || isTypeAssignableTo(getRestrictiveInstantiation(maybeVariable), getRestrictiveInstantiation(sub))) { return maybeVariable; } - return sub; + return filterType(sub, t => !(t.flags & TypeFlags.Negated)); // TODO: Filtering out negated types on nonconcrete instances is a loss of precision } } return type; @@ -12289,11 +12433,11 @@ namespace ts { if (s & TypeFlags.StringLike && t & TypeFlags.String) return true; if (s & TypeFlags.StringLiteral && s & TypeFlags.EnumLiteral && t & TypeFlags.StringLiteral && !(t & TypeFlags.EnumLiteral) && - (source).value === (target).value) return true; + (source).value === (target).value) return true; if (s & TypeFlags.NumberLike && t & TypeFlags.Number) return true; if (s & TypeFlags.NumberLiteral && s & TypeFlags.EnumLiteral && t & TypeFlags.NumberLiteral && !(t & TypeFlags.EnumLiteral) && - (source).value === (target).value) return true; + (source).value === (target).value) return true; if (s & TypeFlags.BigIntLike && t & TypeFlags.BigInt) return true; if (s & TypeFlags.BooleanLike && t & TypeFlags.Boolean) return true; if (s & TypeFlags.ESSymbolLike && t & TypeFlags.ESSymbol) return true; @@ -12557,7 +12701,6 @@ namespace ts { if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) || isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True; - const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes); const isPerformingExcessPropertyChecks = (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral); if (isPerformingExcessPropertyChecks) { const discriminantType = target.flags & TypeFlags.Union ? findMatchingDiscriminantType(source, target as UnionType) : undefined; @@ -12573,7 +12716,7 @@ namespace ts { source.flags & (TypeFlags.Primitive | TypeFlags.Object | TypeFlags.Intersection) && source !== globalObjectType && target.flags & (TypeFlags.Object | TypeFlags.Intersection) && isWeakType(target) && (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source)) && - !hasCommonProperties(source, target, isComparingJsxAttributes)) { + !hasCommonProperties(source, target, !!(getObjectFlags(source) & ObjectFlags.JsxAttributes))) { if (reportErrors) { const calls = getSignaturesOfType(source, SignatureKind.Call); const constructs = getSignaturesOfType(source, SignatureKind.Construct); @@ -12636,6 +12779,22 @@ namespace ts { // - For a primitive type or type parameter (such as 'number = A & B') there is no point in // breaking the intersection apart. result = someTypeRelatedToType(source, target, /*reportErrors*/ false); + if (relation === comparableRelation) { + // In the comparable relation, we may have, eg, `string & not "a"` being related to `"a"` + // `string` and `"a"` are usually comparable - it's only the additional domain limiting + // provided by the negated intersection that narrows further + // So we collect the negated domain bits and see if the target is comparable with those. + // If there's any negated domain bit for which it's not comparable, then the intersection + // as a whole shouldn't be comparable. + const negations = filter((source).types, t => !!(t.flags & TypeFlags.Negated)); + if (length(negations)) { + for (const negation of negations) { + if (!(result &= isRelatedTo(target, negation))) { + break; + } + } + } + } } if (!result && (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable)) { if (result = recursiveTypeRelatedTo(source, target, reportErrors, isIntersectionConstituent)) { @@ -12677,7 +12836,7 @@ namespace ts { else if (source.symbol && source.flags & TypeFlags.Object && globalObjectType === source) { reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); } - else if (isComparingJsxAttributes && target.flags & TypeFlags.Intersection) { + else if (!!(getObjectFlags(source) & ObjectFlags.JsxAttributes) && target.flags & TypeFlags.Intersection) { const targetTypes = (target as IntersectionType).types; const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode); const intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode); @@ -13118,6 +13277,9 @@ namespace ts { if (flags & TypeFlags.Substitution) { return isRelatedTo((source).substitute, (target).substitute, /*reportErrors*/ false); } + if (flags & TypeFlags.Negated) { + return isRelatedTo((source as NegatedType).type, (target as NegatedType).type); + } return Ternary.False; } @@ -13291,6 +13453,29 @@ namespace ts { } } } + else if (target.flags & TypeFlags.Negated) { + if (source.flags & TypeFlags.Negated) { + // ~S is a subset of ~T iff T is a subset of S + return isRelatedTo((target as NegatedType).type, (source as NegatedType).type); + } + if (isObjectLiteralType(source)) { + const result = isRelatedTo(source, (target as NegatedType).type); + return result === Ternary.Maybe ? Ternary.Maybe : result ? Ternary.False : Ternary.True; + } + // Relationship check is S contained in T + // A type S is a subset of ~T if S has no overlap with T (there exist no values within S which are in T) by definition + // however, checking this directly is pretty hard. So instead we rephrase it - + // S contained in ~T is true if S and T share no overlap - that overlap is their _intersection_. This means + // That S contained in ~T is true if (S & T) is `never` (or effectively `never`, since intersections are not eagerly simplified) + // Object literals get to skip this check, since they are effectively closed, having both an upper and lower bound of themselves + if (isIntersectionEmpty(source, (target as NegatedType).type)) { + return Ternary.True; + } + return Ternary.False; + } + else if (source.flags & TypeFlags.Negated) { + return Ternary.False; + } else { // An empty object type is related to any mapped type that includes a '?' modifier. if (relation !== subtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) { @@ -15034,7 +15219,8 @@ namespace ts { // results for union and intersection types for performance reasons. function couldContainTypeVariables(type: Type): boolean { const objectFlags = getObjectFlags(type); - return !!(type.flags & TypeFlags.Instantiable || + return !!(type.flags & (TypeFlags.Instantiable & ~TypeFlags.Negated) || + type.flags & TypeFlags.Negated && couldContainTypeVariables((type as NegatedType).type) || objectFlags & ObjectFlags.Reference && forEach((type).typeArguments, couldContainTypeVariables) || objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations || objectFlags & ObjectFlags.Mapped || @@ -15300,7 +15486,7 @@ namespace ts { const indexType = getSimplifiedType((target as IndexedAccessType).indexType, /*writing*/ false); // Generally simplifications of instantiable indexes are avoided to keep relationship checking correct, however if our target is an access, we can consider // that key of that access to be "instantiated", since we're looking to find the infernce goal in any way we can. - if (indexType.flags & TypeFlags.Instantiable) { + if (indexType.flags & (TypeFlags.Instantiable & ~TypeFlags.Negated)) { const simplified = distributeIndexOverObjectType(getSimplifiedType((target as IndexedAccessType).objectType, /*writing*/ false), indexType, /*writing*/ false); if (simplified && simplified !== target) { inferFromTypesOnce(source, simplified); @@ -15337,6 +15523,11 @@ namespace ts { inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target)); inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target)); } + else if (source.flags & TypeFlags.Negated && target.flags & TypeFlags.Negated) { + contravariant = !contravariant; + inferFromTypes((source as NegatedType).type, (target as NegatedType).type); + contravariant = !contravariant; + } else if (target.flags & TypeFlags.Conditional && !contravariant) { inferFromTypes(source, getTrueTypeFromConditionalType(target)); inferFromTypes(source, getFalseTypeFromConditionalType(target)); @@ -15377,7 +15568,7 @@ namespace ts { } } else { - if (!(priority & InferencePriority.NoConstraints && source.flags & (TypeFlags.Intersection | TypeFlags.Instantiable))) { + if (!(priority & InferencePriority.NoConstraints && source.flags & (TypeFlags.Intersection | (TypeFlags.Instantiable & ~TypeFlags.Negated)))) { const apparentSource = getApparentType(source); // getApparentType can return _any_ type, since an indexed access or conditional may simplify to any other type. // If that occurs and it doesn't simplify to an object or intersection, we'll need to restart `inferFromTypes` @@ -16100,6 +16291,9 @@ namespace ts { if (flags & TypeFlags.NonPrimitive) { return strictNullChecks ? TypeFacts.ObjectStrictFacts : TypeFacts.ObjectFacts; } + if (flags & TypeFlags.Negated) { + return TypeFacts.All; // Specific combinations of negations may remove type facts, but generally they do not imply any narrowing of applicable facts + } if (flags & TypeFlags.Instantiable) { return getTypeFacts(getBaseConstraintOfType(type) || unknownType); } @@ -18769,7 +18963,7 @@ namespace ts { // If the given contextual type contains instantiable types and if a mapper representing // return type inferences is available, instantiate those types using that mapper. function instantiateContextualType(contextualType: Type | undefined, node: Expression, contextFlags?: ContextFlags): Type | undefined { - if (contextualType && maybeTypeOfKind(contextualType, TypeFlags.Instantiable)) { + if (contextualType && maybeTypeOfKindUnwrapNegations(contextualType, TypeFlags.Instantiable)) { const inferenceContext = getInferenceContext(node); // If no inferences have been made, nothing is gained from instantiating as type parameters // would just be replaced with their defaults similar to the apparent type. @@ -23502,6 +23696,24 @@ namespace ts { return false; } + function maybeTypeOfKindUnwrapNegations(type: Type, kind: TypeFlags): boolean { + if (type.flags & TypeFlags.Negated) { + type = (type as NegatedType).type; + } + if (type.flags & kind & ~TypeFlags.GenericMappedType || kind & TypeFlags.GenericMappedType && isGenericMappedType(type)) { + return true; + } + if (type.flags & TypeFlags.UnionOrIntersection) { + const types = (type).types; + for (const t of types) { + if (maybeTypeOfKindUnwrapNegations(t, kind)) { + return true; + } + } + } + return false; + } + function isTypeAssignableToKind(source: Type, kind: TypeFlags, strict?: boolean): boolean { if (source.flags & kind) { return true; @@ -24268,6 +24480,9 @@ namespace ts { const types = (contextualType).types; return some(types, t => isLiteralOfContextualType(candidateType, t)); } + if (contextualType.flags & TypeFlags.Negated) { + contextualType = (contextualType as NegatedType).type; + } 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 diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index f67ec39b0a47e..1a1dac1244704 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -876,8 +876,8 @@ namespace ts { } export function createTypeOperatorNode(type: TypeNode): TypeOperatorNode; - export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode; - export function createTypeOperatorNode(operatorOrType: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | TypeNode, type?: TypeNode) { + export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword, type: TypeNode): TypeOperatorNode; + export function createTypeOperatorNode(operatorOrType: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword | TypeNode, type?: TypeNode) { const node = createSynthesizedNode(SyntaxKind.TypeOperator) as TypeOperatorNode; node.operator = typeof operatorOrType === "number" ? operatorOrType : SyntaxKind.KeyOfKeyword; node.type = parenthesizeElementTypeMember(typeof operatorOrType === "number" ? type! : operatorOrType); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e56ff98846ed6..50e7526d5d09b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3093,7 +3093,7 @@ namespace ts { return finishNode(postfix); } - function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) { + function parseTypeOperator(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword) { const node = createNode(SyntaxKind.TypeOperator); parseExpected(operator); node.operator = operator; @@ -3116,6 +3116,7 @@ namespace ts { case SyntaxKind.KeyOfKeyword: case SyntaxKind.UniqueKeyword: case SyntaxKind.ReadonlyKeyword: + case SyntaxKind.NotKeyword: return parseTypeOperator(operator); case SyntaxKind.InferKeyword: return parseInferType(); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 36ac8adfa9053..695acd25cedde 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -98,6 +98,7 @@ namespace ts { interface: SyntaxKind.InterfaceKeyword, is: SyntaxKind.IsKeyword, keyof: SyntaxKind.KeyOfKeyword, + not: SyntaxKind.NotKeyword, let: SyntaxKind.LetKeyword, module: SyntaxKind.ModuleKeyword, namespace: SyntaxKind.NamespaceKeyword, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4442f339d838e..de1e96039aa13 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -64,6 +64,7 @@ namespace ts { | SyntaxKind.InterfaceKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword + | SyntaxKind.NotKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword @@ -259,6 +260,7 @@ namespace ts { InferKeyword, IsKeyword, KeyOfKeyword, + NotKeyword, ModuleKeyword, NamespaceKeyword, NeverKeyword, @@ -1242,7 +1244,7 @@ namespace ts { export interface TypeOperatorNode extends TypeNode { kind: SyntaxKind.TypeOperator; - operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; + operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword; type: TypeNode; } @@ -3938,6 +3940,7 @@ namespace ts { Conditional = 1 << 24, // T extends U ? X : Y Substitution = 1 << 25, // Type parameter substitution NonPrimitive = 1 << 26, // intrinsic object type + Negated = 1 << 27, // negated type /* @internal */ AnyOrUnknown = Any | Unknown, @@ -3967,7 +3970,7 @@ namespace ts { UnionOrIntersection = Union | Intersection, StructuredType = Object | Union | Intersection, TypeVariable = TypeParameter | IndexedAccess, - InstantiableNonPrimitive = TypeVariable | Conditional | Substitution, + InstantiableNonPrimitive = TypeVariable | Conditional | Substitution | Negated, InstantiablePrimitive = Index, Instantiable = InstantiableNonPrimitive | InstantiablePrimitive, StructuredOrInstantiable = StructuredType | Instantiable, @@ -3983,16 +3986,16 @@ namespace ts { NotPrimitiveUnion = Any | Unknown | Enum | Void | Never | StructuredOrInstantiable, // The following flags are aggregated during union and intersection type construction /* @internal */ - IncludesMask = Any | Unknown | Primitive | Never | Object | Union | NonPrimitive, + IncludesMask = Any | Unknown | Primitive | Never | Object | Union | NonPrimitive | Negated | TypeVariable, // The following flags are used for different purposes during union and intersection type construction /* @internal */ - IncludesStructuredOrInstantiable = TypeParameter, + IncludesStructuredOrInstantiable = Conditional, /* @internal */ IncludesNonWideningType = Intersection, /* @internal */ IncludesWildcard = Index, /* @internal */ - IncludesEmptyObject = IndexedAccess, + IncludesEmptyObject = Substitution, // The following flag is used for different purposes by maybeTypeOfKind /* @internal */ GenericMappedType = Never, @@ -4072,6 +4075,11 @@ namespace ts { export interface EnumType extends Type { } + // Negated types (TypeFlags.Negated) + export interface NegatedType extends Type { + type: Type; + } + export const enum ObjectFlags { Class = 1 << 0, // Class Interface = 1 << 1, // Interface @@ -4357,11 +4365,15 @@ namespace ts { /* @internal */ resolvedInferredTrueType?: Type; // The `trueType` instantiated with the `combinedMapper`, if present /* @internal */ + resolvedInferredFalseType?: Type; // Likewise, the `falseType` with the `falseCombinedMapper` + /* @internal */ resolvedDefaultConstraint?: Type; /* @internal */ mapper?: TypeMapper; /* @internal */ combinedMapper?: TypeMapper; + /* @internal */ + falseCombinedMapper?: TypeMapper; } // Type parameter substitution (TypeFlags.Substitution) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c26b059ced8e5..786285aab3a4f 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -4560,7 +4560,7 @@ namespace FourSlashInterface { export const keywords: ReadonlyArray = keywordsWithUndefined.filter(k => k.name !== "undefined"); export const typeKeywords: ReadonlyArray = - ["false", "null", "true", "void", "any", "boolean", "keyof", "never", "number", "object", "string", "symbol", "undefined", "unique", "unknown", "bigint"].map(keywordEntry); + ["false", "null", "true", "void", "any", "boolean", "keyof", "not", "never", "number", "object", "string", "symbol", "undefined", "unique", "unknown", "bigint"].map(keywordEntry); const globalTypeDecls: ReadonlyArray = [ interfaceEntry("Symbol"), @@ -4823,6 +4823,7 @@ namespace FourSlashInterface { "infer", "is", "keyof", + "not", "module", "namespace", "never", @@ -5037,6 +5038,7 @@ namespace FourSlashInterface { "infer", "is", "keyof", + "not", "module", "namespace", "never", diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 35fca7f0e65fa..a7b9a84f48601 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1220,6 +1220,7 @@ namespace ts { SyntaxKind.BooleanKeyword, SyntaxKind.FalseKeyword, SyntaxKind.KeyOfKeyword, + SyntaxKind.NotKeyword, SyntaxKind.NeverKeyword, SyntaxKind.NullKeyword, SyntaxKind.NumberKeyword, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 82ab70b6e6fe6..f35897cd19a68 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -73,7 +73,7 @@ declare namespace ts { end: number; } type JSDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.BacktickToken | SyntaxKind.Unknown | KeywordSyntaxKind; - type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InKeyword | SyntaxKind.InferKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.OfKeyword; + type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InKeyword | SyntaxKind.InferKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.NotKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.OfKeyword; type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; enum SyntaxKind { Unknown = 0, @@ -208,194 +208,195 @@ declare namespace ts { InferKeyword = 128, IsKeyword = 129, KeyOfKeyword = 130, - ModuleKeyword = 131, - NamespaceKeyword = 132, - NeverKeyword = 133, - ReadonlyKeyword = 134, - RequireKeyword = 135, - NumberKeyword = 136, - ObjectKeyword = 137, - SetKeyword = 138, - StringKeyword = 139, - SymbolKeyword = 140, - TypeKeyword = 141, - UndefinedKeyword = 142, - UniqueKeyword = 143, - UnknownKeyword = 144, - FromKeyword = 145, - GlobalKeyword = 146, - BigIntKeyword = 147, - OfKeyword = 148, - QualifiedName = 149, - ComputedPropertyName = 150, - TypeParameter = 151, - Parameter = 152, - Decorator = 153, - PropertySignature = 154, - PropertyDeclaration = 155, - MethodSignature = 156, - MethodDeclaration = 157, - Constructor = 158, - GetAccessor = 159, - SetAccessor = 160, - CallSignature = 161, - ConstructSignature = 162, - IndexSignature = 163, - TypePredicate = 164, - TypeReference = 165, - FunctionType = 166, - ConstructorType = 167, - TypeQuery = 168, - TypeLiteral = 169, - ArrayType = 170, - TupleType = 171, - OptionalType = 172, - RestType = 173, - UnionType = 174, - IntersectionType = 175, - ConditionalType = 176, - InferType = 177, - ParenthesizedType = 178, - ThisType = 179, - TypeOperator = 180, - IndexedAccessType = 181, - MappedType = 182, - LiteralType = 183, - ImportType = 184, - ObjectBindingPattern = 185, - ArrayBindingPattern = 186, - BindingElement = 187, - ArrayLiteralExpression = 188, - ObjectLiteralExpression = 189, - PropertyAccessExpression = 190, - ElementAccessExpression = 191, - CallExpression = 192, - NewExpression = 193, - TaggedTemplateExpression = 194, - TypeAssertionExpression = 195, - ParenthesizedExpression = 196, - FunctionExpression = 197, - ArrowFunction = 198, - DeleteExpression = 199, - TypeOfExpression = 200, - VoidExpression = 201, - AwaitExpression = 202, - PrefixUnaryExpression = 203, - PostfixUnaryExpression = 204, - BinaryExpression = 205, - ConditionalExpression = 206, - TemplateExpression = 207, - YieldExpression = 208, - SpreadElement = 209, - ClassExpression = 210, - OmittedExpression = 211, - ExpressionWithTypeArguments = 212, - AsExpression = 213, - NonNullExpression = 214, - MetaProperty = 215, - SyntheticExpression = 216, - TemplateSpan = 217, - SemicolonClassElement = 218, - Block = 219, - VariableStatement = 220, - EmptyStatement = 221, - ExpressionStatement = 222, - IfStatement = 223, - DoStatement = 224, - WhileStatement = 225, - ForStatement = 226, - ForInStatement = 227, - ForOfStatement = 228, - ContinueStatement = 229, - BreakStatement = 230, - ReturnStatement = 231, - WithStatement = 232, - SwitchStatement = 233, - LabeledStatement = 234, - ThrowStatement = 235, - TryStatement = 236, - DebuggerStatement = 237, - VariableDeclaration = 238, - VariableDeclarationList = 239, - FunctionDeclaration = 240, - ClassDeclaration = 241, - InterfaceDeclaration = 242, - TypeAliasDeclaration = 243, - EnumDeclaration = 244, - ModuleDeclaration = 245, - ModuleBlock = 246, - CaseBlock = 247, - NamespaceExportDeclaration = 248, - ImportEqualsDeclaration = 249, - ImportDeclaration = 250, - ImportClause = 251, - NamespaceImport = 252, - NamedImports = 253, - ImportSpecifier = 254, - ExportAssignment = 255, - ExportDeclaration = 256, - NamedExports = 257, - ExportSpecifier = 258, - MissingDeclaration = 259, - ExternalModuleReference = 260, - JsxElement = 261, - JsxSelfClosingElement = 262, - JsxOpeningElement = 263, - JsxClosingElement = 264, - JsxFragment = 265, - JsxOpeningFragment = 266, - JsxClosingFragment = 267, - JsxAttribute = 268, - JsxAttributes = 269, - JsxSpreadAttribute = 270, - JsxExpression = 271, - CaseClause = 272, - DefaultClause = 273, - HeritageClause = 274, - CatchClause = 275, - PropertyAssignment = 276, - ShorthandPropertyAssignment = 277, - SpreadAssignment = 278, - EnumMember = 279, - UnparsedPrologue = 280, - UnparsedPrepend = 281, - UnparsedText = 282, - UnparsedInternalText = 283, - UnparsedSyntheticReference = 284, - SourceFile = 285, - Bundle = 286, - UnparsedSource = 287, - InputFiles = 288, - JSDocTypeExpression = 289, - JSDocAllType = 290, - JSDocUnknownType = 291, - JSDocNullableType = 292, - JSDocNonNullableType = 293, - JSDocOptionalType = 294, - JSDocFunctionType = 295, - JSDocVariadicType = 296, - JSDocComment = 297, - JSDocTypeLiteral = 298, - JSDocSignature = 299, - JSDocTag = 300, - JSDocAugmentsTag = 301, - JSDocClassTag = 302, - JSDocCallbackTag = 303, - JSDocEnumTag = 304, - JSDocParameterTag = 305, - JSDocReturnTag = 306, - JSDocThisTag = 307, - JSDocTypeTag = 308, - JSDocTemplateTag = 309, - JSDocTypedefTag = 310, - JSDocPropertyTag = 311, - SyntaxList = 312, - NotEmittedStatement = 313, - PartiallyEmittedExpression = 314, - CommaListExpression = 315, - MergeDeclarationMarker = 316, - EndOfDeclarationMarker = 317, - Count = 318, + NotKeyword = 131, + ModuleKeyword = 132, + NamespaceKeyword = 133, + NeverKeyword = 134, + ReadonlyKeyword = 135, + RequireKeyword = 136, + NumberKeyword = 137, + ObjectKeyword = 138, + SetKeyword = 139, + StringKeyword = 140, + SymbolKeyword = 141, + TypeKeyword = 142, + UndefinedKeyword = 143, + UniqueKeyword = 144, + UnknownKeyword = 145, + FromKeyword = 146, + GlobalKeyword = 147, + BigIntKeyword = 148, + OfKeyword = 149, + QualifiedName = 150, + ComputedPropertyName = 151, + TypeParameter = 152, + Parameter = 153, + Decorator = 154, + PropertySignature = 155, + PropertyDeclaration = 156, + MethodSignature = 157, + MethodDeclaration = 158, + Constructor = 159, + GetAccessor = 160, + SetAccessor = 161, + CallSignature = 162, + ConstructSignature = 163, + IndexSignature = 164, + TypePredicate = 165, + TypeReference = 166, + FunctionType = 167, + ConstructorType = 168, + TypeQuery = 169, + TypeLiteral = 170, + ArrayType = 171, + TupleType = 172, + OptionalType = 173, + RestType = 174, + UnionType = 175, + IntersectionType = 176, + ConditionalType = 177, + InferType = 178, + ParenthesizedType = 179, + ThisType = 180, + TypeOperator = 181, + IndexedAccessType = 182, + MappedType = 183, + LiteralType = 184, + ImportType = 185, + ObjectBindingPattern = 186, + ArrayBindingPattern = 187, + BindingElement = 188, + ArrayLiteralExpression = 189, + ObjectLiteralExpression = 190, + PropertyAccessExpression = 191, + ElementAccessExpression = 192, + CallExpression = 193, + NewExpression = 194, + TaggedTemplateExpression = 195, + TypeAssertionExpression = 196, + ParenthesizedExpression = 197, + FunctionExpression = 198, + ArrowFunction = 199, + DeleteExpression = 200, + TypeOfExpression = 201, + VoidExpression = 202, + AwaitExpression = 203, + PrefixUnaryExpression = 204, + PostfixUnaryExpression = 205, + BinaryExpression = 206, + ConditionalExpression = 207, + TemplateExpression = 208, + YieldExpression = 209, + SpreadElement = 210, + ClassExpression = 211, + OmittedExpression = 212, + ExpressionWithTypeArguments = 213, + AsExpression = 214, + NonNullExpression = 215, + MetaProperty = 216, + SyntheticExpression = 217, + TemplateSpan = 218, + SemicolonClassElement = 219, + Block = 220, + VariableStatement = 221, + EmptyStatement = 222, + ExpressionStatement = 223, + IfStatement = 224, + DoStatement = 225, + WhileStatement = 226, + ForStatement = 227, + ForInStatement = 228, + ForOfStatement = 229, + ContinueStatement = 230, + BreakStatement = 231, + ReturnStatement = 232, + WithStatement = 233, + SwitchStatement = 234, + LabeledStatement = 235, + ThrowStatement = 236, + TryStatement = 237, + DebuggerStatement = 238, + VariableDeclaration = 239, + VariableDeclarationList = 240, + FunctionDeclaration = 241, + ClassDeclaration = 242, + InterfaceDeclaration = 243, + TypeAliasDeclaration = 244, + EnumDeclaration = 245, + ModuleDeclaration = 246, + ModuleBlock = 247, + CaseBlock = 248, + NamespaceExportDeclaration = 249, + ImportEqualsDeclaration = 250, + ImportDeclaration = 251, + ImportClause = 252, + NamespaceImport = 253, + NamedImports = 254, + ImportSpecifier = 255, + ExportAssignment = 256, + ExportDeclaration = 257, + NamedExports = 258, + ExportSpecifier = 259, + MissingDeclaration = 260, + ExternalModuleReference = 261, + JsxElement = 262, + JsxSelfClosingElement = 263, + JsxOpeningElement = 264, + JsxClosingElement = 265, + JsxFragment = 266, + JsxOpeningFragment = 267, + JsxClosingFragment = 268, + JsxAttribute = 269, + JsxAttributes = 270, + JsxSpreadAttribute = 271, + JsxExpression = 272, + CaseClause = 273, + DefaultClause = 274, + HeritageClause = 275, + CatchClause = 276, + PropertyAssignment = 277, + ShorthandPropertyAssignment = 278, + SpreadAssignment = 279, + EnumMember = 280, + UnparsedPrologue = 281, + UnparsedPrepend = 282, + UnparsedText = 283, + UnparsedInternalText = 284, + UnparsedSyntheticReference = 285, + SourceFile = 286, + Bundle = 287, + UnparsedSource = 288, + InputFiles = 289, + JSDocTypeExpression = 290, + JSDocAllType = 291, + JSDocUnknownType = 292, + JSDocNullableType = 293, + JSDocNonNullableType = 294, + JSDocOptionalType = 295, + JSDocFunctionType = 296, + JSDocVariadicType = 297, + JSDocComment = 298, + JSDocTypeLiteral = 299, + JSDocSignature = 300, + JSDocTag = 301, + JSDocAugmentsTag = 302, + JSDocClassTag = 303, + JSDocCallbackTag = 304, + JSDocEnumTag = 305, + JSDocParameterTag = 306, + JSDocReturnTag = 307, + JSDocThisTag = 308, + JSDocTypeTag = 309, + JSDocTemplateTag = 310, + JSDocTypedefTag = 311, + JSDocPropertyTag = 312, + SyntaxList = 313, + NotEmittedStatement = 314, + PartiallyEmittedExpression = 315, + CommaListExpression = 316, + MergeDeclarationMarker = 317, + EndOfDeclarationMarker = 318, + Count = 319, FirstAssignment = 60, LastAssignment = 72, FirstCompoundAssignment = 61, @@ -403,15 +404,15 @@ declare namespace ts { FirstReservedWord = 74, LastReservedWord = 109, FirstKeyword = 74, - LastKeyword = 148, + LastKeyword = 149, FirstFutureReservedWord = 110, LastFutureReservedWord = 118, - FirstTypeNode = 164, - LastTypeNode = 184, + FirstTypeNode = 165, + LastTypeNode = 185, FirstPunctuation = 18, LastPunctuation = 72, FirstToken = 0, - LastToken = 148, + LastToken = 149, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -420,11 +421,11 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 28, LastBinaryOperator = 72, - FirstNode = 149, - FirstJSDocNode = 289, - LastJSDocNode = 311, - FirstJSDocTagNode = 300, - LastJSDocTagNode = 311, + FirstNode = 150, + FirstJSDocNode = 290, + LastJSDocNode = 312, + FirstJSDocTagNode = 301, + LastJSDocTagNode = 312, } enum NodeFlags { None = 0, @@ -821,7 +822,7 @@ declare namespace ts { } interface TypeOperatorNode extends TypeNode { kind: SyntaxKind.TypeOperator; - operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; + operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword; type: TypeNode; } interface IndexedAccessTypeNode extends TypeNode { @@ -2237,6 +2238,7 @@ declare namespace ts { Conditional = 16777216, Substitution = 33554432, NonPrimitive = 67108864, + Negated = 134217728, Literal = 2944, Unit = 109440, StringOrNumberLiteral = 384, @@ -2251,11 +2253,11 @@ declare namespace ts { UnionOrIntersection = 3145728, StructuredType = 3670016, TypeVariable = 8650752, - InstantiableNonPrimitive = 58982400, + InstantiableNonPrimitive = 193200128, InstantiablePrimitive = 4194304, - Instantiable = 63176704, - StructuredOrInstantiable = 66846720, - Narrowable = 133970943, + Instantiable = 197394432, + StructuredOrInstantiable = 201064448, + Narrowable = 268188671, NotUnionOrUnit = 67637251, } type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; @@ -2286,6 +2288,9 @@ declare namespace ts { } interface EnumType extends Type { } + interface NegatedType extends Type { + type: Type; + } enum ObjectFlags { Class = 1, Interface = 2, @@ -3847,7 +3852,7 @@ declare namespace ts { function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; function createThisTypeNode(): ThisTypeNode; function createTypeOperatorNode(type: TypeNode): TypeOperatorNode; - function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode; + function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword, type: TypeNode): TypeOperatorNode; function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode): TypeOperatorNode; function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode; function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0c55cff12757c..5e2ae974d01c9 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -73,7 +73,7 @@ declare namespace ts { end: number; } type JSDocSyntaxKind = SyntaxKind.EndOfFileToken | SyntaxKind.WhitespaceTrivia | SyntaxKind.AtToken | SyntaxKind.NewLineTrivia | SyntaxKind.AsteriskToken | SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.LessThanToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.EqualsToken | SyntaxKind.CommaToken | SyntaxKind.DotToken | SyntaxKind.Identifier | SyntaxKind.BacktickToken | SyntaxKind.Unknown | KeywordSyntaxKind; - type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InKeyword | SyntaxKind.InferKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.OfKeyword; + type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InKeyword | SyntaxKind.InferKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.NotKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.OfKeyword; type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; enum SyntaxKind { Unknown = 0, @@ -208,194 +208,195 @@ declare namespace ts { InferKeyword = 128, IsKeyword = 129, KeyOfKeyword = 130, - ModuleKeyword = 131, - NamespaceKeyword = 132, - NeverKeyword = 133, - ReadonlyKeyword = 134, - RequireKeyword = 135, - NumberKeyword = 136, - ObjectKeyword = 137, - SetKeyword = 138, - StringKeyword = 139, - SymbolKeyword = 140, - TypeKeyword = 141, - UndefinedKeyword = 142, - UniqueKeyword = 143, - UnknownKeyword = 144, - FromKeyword = 145, - GlobalKeyword = 146, - BigIntKeyword = 147, - OfKeyword = 148, - QualifiedName = 149, - ComputedPropertyName = 150, - TypeParameter = 151, - Parameter = 152, - Decorator = 153, - PropertySignature = 154, - PropertyDeclaration = 155, - MethodSignature = 156, - MethodDeclaration = 157, - Constructor = 158, - GetAccessor = 159, - SetAccessor = 160, - CallSignature = 161, - ConstructSignature = 162, - IndexSignature = 163, - TypePredicate = 164, - TypeReference = 165, - FunctionType = 166, - ConstructorType = 167, - TypeQuery = 168, - TypeLiteral = 169, - ArrayType = 170, - TupleType = 171, - OptionalType = 172, - RestType = 173, - UnionType = 174, - IntersectionType = 175, - ConditionalType = 176, - InferType = 177, - ParenthesizedType = 178, - ThisType = 179, - TypeOperator = 180, - IndexedAccessType = 181, - MappedType = 182, - LiteralType = 183, - ImportType = 184, - ObjectBindingPattern = 185, - ArrayBindingPattern = 186, - BindingElement = 187, - ArrayLiteralExpression = 188, - ObjectLiteralExpression = 189, - PropertyAccessExpression = 190, - ElementAccessExpression = 191, - CallExpression = 192, - NewExpression = 193, - TaggedTemplateExpression = 194, - TypeAssertionExpression = 195, - ParenthesizedExpression = 196, - FunctionExpression = 197, - ArrowFunction = 198, - DeleteExpression = 199, - TypeOfExpression = 200, - VoidExpression = 201, - AwaitExpression = 202, - PrefixUnaryExpression = 203, - PostfixUnaryExpression = 204, - BinaryExpression = 205, - ConditionalExpression = 206, - TemplateExpression = 207, - YieldExpression = 208, - SpreadElement = 209, - ClassExpression = 210, - OmittedExpression = 211, - ExpressionWithTypeArguments = 212, - AsExpression = 213, - NonNullExpression = 214, - MetaProperty = 215, - SyntheticExpression = 216, - TemplateSpan = 217, - SemicolonClassElement = 218, - Block = 219, - VariableStatement = 220, - EmptyStatement = 221, - ExpressionStatement = 222, - IfStatement = 223, - DoStatement = 224, - WhileStatement = 225, - ForStatement = 226, - ForInStatement = 227, - ForOfStatement = 228, - ContinueStatement = 229, - BreakStatement = 230, - ReturnStatement = 231, - WithStatement = 232, - SwitchStatement = 233, - LabeledStatement = 234, - ThrowStatement = 235, - TryStatement = 236, - DebuggerStatement = 237, - VariableDeclaration = 238, - VariableDeclarationList = 239, - FunctionDeclaration = 240, - ClassDeclaration = 241, - InterfaceDeclaration = 242, - TypeAliasDeclaration = 243, - EnumDeclaration = 244, - ModuleDeclaration = 245, - ModuleBlock = 246, - CaseBlock = 247, - NamespaceExportDeclaration = 248, - ImportEqualsDeclaration = 249, - ImportDeclaration = 250, - ImportClause = 251, - NamespaceImport = 252, - NamedImports = 253, - ImportSpecifier = 254, - ExportAssignment = 255, - ExportDeclaration = 256, - NamedExports = 257, - ExportSpecifier = 258, - MissingDeclaration = 259, - ExternalModuleReference = 260, - JsxElement = 261, - JsxSelfClosingElement = 262, - JsxOpeningElement = 263, - JsxClosingElement = 264, - JsxFragment = 265, - JsxOpeningFragment = 266, - JsxClosingFragment = 267, - JsxAttribute = 268, - JsxAttributes = 269, - JsxSpreadAttribute = 270, - JsxExpression = 271, - CaseClause = 272, - DefaultClause = 273, - HeritageClause = 274, - CatchClause = 275, - PropertyAssignment = 276, - ShorthandPropertyAssignment = 277, - SpreadAssignment = 278, - EnumMember = 279, - UnparsedPrologue = 280, - UnparsedPrepend = 281, - UnparsedText = 282, - UnparsedInternalText = 283, - UnparsedSyntheticReference = 284, - SourceFile = 285, - Bundle = 286, - UnparsedSource = 287, - InputFiles = 288, - JSDocTypeExpression = 289, - JSDocAllType = 290, - JSDocUnknownType = 291, - JSDocNullableType = 292, - JSDocNonNullableType = 293, - JSDocOptionalType = 294, - JSDocFunctionType = 295, - JSDocVariadicType = 296, - JSDocComment = 297, - JSDocTypeLiteral = 298, - JSDocSignature = 299, - JSDocTag = 300, - JSDocAugmentsTag = 301, - JSDocClassTag = 302, - JSDocCallbackTag = 303, - JSDocEnumTag = 304, - JSDocParameterTag = 305, - JSDocReturnTag = 306, - JSDocThisTag = 307, - JSDocTypeTag = 308, - JSDocTemplateTag = 309, - JSDocTypedefTag = 310, - JSDocPropertyTag = 311, - SyntaxList = 312, - NotEmittedStatement = 313, - PartiallyEmittedExpression = 314, - CommaListExpression = 315, - MergeDeclarationMarker = 316, - EndOfDeclarationMarker = 317, - Count = 318, + NotKeyword = 131, + ModuleKeyword = 132, + NamespaceKeyword = 133, + NeverKeyword = 134, + ReadonlyKeyword = 135, + RequireKeyword = 136, + NumberKeyword = 137, + ObjectKeyword = 138, + SetKeyword = 139, + StringKeyword = 140, + SymbolKeyword = 141, + TypeKeyword = 142, + UndefinedKeyword = 143, + UniqueKeyword = 144, + UnknownKeyword = 145, + FromKeyword = 146, + GlobalKeyword = 147, + BigIntKeyword = 148, + OfKeyword = 149, + QualifiedName = 150, + ComputedPropertyName = 151, + TypeParameter = 152, + Parameter = 153, + Decorator = 154, + PropertySignature = 155, + PropertyDeclaration = 156, + MethodSignature = 157, + MethodDeclaration = 158, + Constructor = 159, + GetAccessor = 160, + SetAccessor = 161, + CallSignature = 162, + ConstructSignature = 163, + IndexSignature = 164, + TypePredicate = 165, + TypeReference = 166, + FunctionType = 167, + ConstructorType = 168, + TypeQuery = 169, + TypeLiteral = 170, + ArrayType = 171, + TupleType = 172, + OptionalType = 173, + RestType = 174, + UnionType = 175, + IntersectionType = 176, + ConditionalType = 177, + InferType = 178, + ParenthesizedType = 179, + ThisType = 180, + TypeOperator = 181, + IndexedAccessType = 182, + MappedType = 183, + LiteralType = 184, + ImportType = 185, + ObjectBindingPattern = 186, + ArrayBindingPattern = 187, + BindingElement = 188, + ArrayLiteralExpression = 189, + ObjectLiteralExpression = 190, + PropertyAccessExpression = 191, + ElementAccessExpression = 192, + CallExpression = 193, + NewExpression = 194, + TaggedTemplateExpression = 195, + TypeAssertionExpression = 196, + ParenthesizedExpression = 197, + FunctionExpression = 198, + ArrowFunction = 199, + DeleteExpression = 200, + TypeOfExpression = 201, + VoidExpression = 202, + AwaitExpression = 203, + PrefixUnaryExpression = 204, + PostfixUnaryExpression = 205, + BinaryExpression = 206, + ConditionalExpression = 207, + TemplateExpression = 208, + YieldExpression = 209, + SpreadElement = 210, + ClassExpression = 211, + OmittedExpression = 212, + ExpressionWithTypeArguments = 213, + AsExpression = 214, + NonNullExpression = 215, + MetaProperty = 216, + SyntheticExpression = 217, + TemplateSpan = 218, + SemicolonClassElement = 219, + Block = 220, + VariableStatement = 221, + EmptyStatement = 222, + ExpressionStatement = 223, + IfStatement = 224, + DoStatement = 225, + WhileStatement = 226, + ForStatement = 227, + ForInStatement = 228, + ForOfStatement = 229, + ContinueStatement = 230, + BreakStatement = 231, + ReturnStatement = 232, + WithStatement = 233, + SwitchStatement = 234, + LabeledStatement = 235, + ThrowStatement = 236, + TryStatement = 237, + DebuggerStatement = 238, + VariableDeclaration = 239, + VariableDeclarationList = 240, + FunctionDeclaration = 241, + ClassDeclaration = 242, + InterfaceDeclaration = 243, + TypeAliasDeclaration = 244, + EnumDeclaration = 245, + ModuleDeclaration = 246, + ModuleBlock = 247, + CaseBlock = 248, + NamespaceExportDeclaration = 249, + ImportEqualsDeclaration = 250, + ImportDeclaration = 251, + ImportClause = 252, + NamespaceImport = 253, + NamedImports = 254, + ImportSpecifier = 255, + ExportAssignment = 256, + ExportDeclaration = 257, + NamedExports = 258, + ExportSpecifier = 259, + MissingDeclaration = 260, + ExternalModuleReference = 261, + JsxElement = 262, + JsxSelfClosingElement = 263, + JsxOpeningElement = 264, + JsxClosingElement = 265, + JsxFragment = 266, + JsxOpeningFragment = 267, + JsxClosingFragment = 268, + JsxAttribute = 269, + JsxAttributes = 270, + JsxSpreadAttribute = 271, + JsxExpression = 272, + CaseClause = 273, + DefaultClause = 274, + HeritageClause = 275, + CatchClause = 276, + PropertyAssignment = 277, + ShorthandPropertyAssignment = 278, + SpreadAssignment = 279, + EnumMember = 280, + UnparsedPrologue = 281, + UnparsedPrepend = 282, + UnparsedText = 283, + UnparsedInternalText = 284, + UnparsedSyntheticReference = 285, + SourceFile = 286, + Bundle = 287, + UnparsedSource = 288, + InputFiles = 289, + JSDocTypeExpression = 290, + JSDocAllType = 291, + JSDocUnknownType = 292, + JSDocNullableType = 293, + JSDocNonNullableType = 294, + JSDocOptionalType = 295, + JSDocFunctionType = 296, + JSDocVariadicType = 297, + JSDocComment = 298, + JSDocTypeLiteral = 299, + JSDocSignature = 300, + JSDocTag = 301, + JSDocAugmentsTag = 302, + JSDocClassTag = 303, + JSDocCallbackTag = 304, + JSDocEnumTag = 305, + JSDocParameterTag = 306, + JSDocReturnTag = 307, + JSDocThisTag = 308, + JSDocTypeTag = 309, + JSDocTemplateTag = 310, + JSDocTypedefTag = 311, + JSDocPropertyTag = 312, + SyntaxList = 313, + NotEmittedStatement = 314, + PartiallyEmittedExpression = 315, + CommaListExpression = 316, + MergeDeclarationMarker = 317, + EndOfDeclarationMarker = 318, + Count = 319, FirstAssignment = 60, LastAssignment = 72, FirstCompoundAssignment = 61, @@ -403,15 +404,15 @@ declare namespace ts { FirstReservedWord = 74, LastReservedWord = 109, FirstKeyword = 74, - LastKeyword = 148, + LastKeyword = 149, FirstFutureReservedWord = 110, LastFutureReservedWord = 118, - FirstTypeNode = 164, - LastTypeNode = 184, + FirstTypeNode = 165, + LastTypeNode = 185, FirstPunctuation = 18, LastPunctuation = 72, FirstToken = 0, - LastToken = 148, + LastToken = 149, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -420,11 +421,11 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 28, LastBinaryOperator = 72, - FirstNode = 149, - FirstJSDocNode = 289, - LastJSDocNode = 311, - FirstJSDocTagNode = 300, - LastJSDocTagNode = 311, + FirstNode = 150, + FirstJSDocNode = 290, + LastJSDocNode = 312, + FirstJSDocTagNode = 301, + LastJSDocTagNode = 312, } enum NodeFlags { None = 0, @@ -821,7 +822,7 @@ declare namespace ts { } interface TypeOperatorNode extends TypeNode { kind: SyntaxKind.TypeOperator; - operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword; + operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword; type: TypeNode; } interface IndexedAccessTypeNode extends TypeNode { @@ -2237,6 +2238,7 @@ declare namespace ts { Conditional = 16777216, Substitution = 33554432, NonPrimitive = 67108864, + Negated = 134217728, Literal = 2944, Unit = 109440, StringOrNumberLiteral = 384, @@ -2251,11 +2253,11 @@ declare namespace ts { UnionOrIntersection = 3145728, StructuredType = 3670016, TypeVariable = 8650752, - InstantiableNonPrimitive = 58982400, + InstantiableNonPrimitive = 193200128, InstantiablePrimitive = 4194304, - Instantiable = 63176704, - StructuredOrInstantiable = 66846720, - Narrowable = 133970943, + Instantiable = 197394432, + StructuredOrInstantiable = 201064448, + Narrowable = 268188671, NotUnionOrUnit = 67637251, } type DestructuringPattern = BindingPattern | ObjectLiteralExpression | ArrayLiteralExpression; @@ -2286,6 +2288,9 @@ declare namespace ts { } interface EnumType extends Type { } + interface NegatedType extends Type { + type: Type; + } enum ObjectFlags { Class = 1, Interface = 2, @@ -3847,7 +3852,7 @@ declare namespace ts { function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; function createThisTypeNode(): ThisTypeNode; function createTypeOperatorNode(type: TypeNode): TypeOperatorNode; - function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword, type: TypeNode): TypeOperatorNode; + function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.NotKeyword, type: TypeNode): TypeOperatorNode; function updateTypeOperatorNode(node: TypeOperatorNode, type: TypeNode): TypeOperatorNode; function createIndexedAccessTypeNode(objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode; function updateIndexedAccessTypeNode(node: IndexedAccessTypeNode, objectType: TypeNode, indexType: TypeNode): IndexedAccessTypeNode; diff --git a/tests/baselines/reference/assignmentCompatability24.errors.txt b/tests/baselines/reference/assignmentCompatability24.errors.txt index 9d200272b31cb..b351cc7b79da2 100644 --- a/tests/baselines/reference/assignmentCompatability24.errors.txt +++ b/tests/baselines/reference/assignmentCompatability24.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/assignmentCompatability24.ts(9,1): error TS2322: Type 'interfaceWithPublicAndOptional' is not assignable to type '(a: Tstring) => Tstring'. - Type 'interfaceWithPublicAndOptional' provides no match for the signature '(a: Tstring): Tstring'. + Property 'one' does not exist on type '(a: Tstring) => Tstring'. ==== tests/cases/compiler/assignmentCompatability24.ts (1 errors) ==== @@ -14,4 +14,4 @@ tests/cases/compiler/assignmentCompatability24.ts(9,1): error TS2322: Type 'inte __test2__.__val__obj = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~~ !!! error TS2322: Type 'interfaceWithPublicAndOptional' is not assignable to type '(a: Tstring) => Tstring'. -!!! error TS2322: Type 'interfaceWithPublicAndOptional' provides no match for the signature '(a: Tstring): Tstring'. \ No newline at end of file +!!! error TS2322: Property 'one' does not exist on type '(a: Tstring) => Tstring'. \ No newline at end of file diff --git a/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt b/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt index 34bd218996483..bb0cbd16dcd8d 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt +++ b/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/jsx/file.tsx(24,28): error TS2551: Property 'NAme' does not exist on type 'IUser'. Did you mean 'Name'? tests/cases/conformance/jsx/file.tsx(36,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement'. - Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement': type, props + Type '(user: IUser) => Element' is not assignable to type 'string'. tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement'. - Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement': type, props + Type '(user: IUser) => Element' is not assignable to type 'string'. ==== tests/cases/conformance/jsx/file.tsx (3 errors) ==== @@ -51,7 +51,7 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) = ) } ~~~~~~~~~~~~~ !!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement'. -!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement': type, props +!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string'. !!! related TS6212 tests/cases/conformance/jsx/file.tsx:36:15: Did you mean to call this expression? { user => ( ~~~~~~~~~ @@ -60,7 +60,7 @@ tests/cases/conformance/jsx/file.tsx(39,15): error TS2322: Type '(user: IUser) = ) } ~~~~~~~~~~~~~ !!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string | number | boolean | any[] | ReactElement'. -!!! error TS2322: Type '(user: IUser) => Element' is missing the following properties from type 'ReactElement': type, props +!!! error TS2322: Type '(user: IUser) => Element' is not assignable to type 'string'. !!! related TS6212 tests/cases/conformance/jsx/file.tsx:39:15: Did you mean to call this expression? ); diff --git a/tests/baselines/reference/checkJsxSubtleSkipContextSensitiveBug.types b/tests/baselines/reference/checkJsxSubtleSkipContextSensitiveBug.types index da2947255e64c..527bff2ac3abb 100644 --- a/tests/baselines/reference/checkJsxSubtleSkipContextSensitiveBug.types +++ b/tests/baselines/reference/checkJsxSubtleSkipContextSensitiveBug.types @@ -48,10 +48,10 @@ const loader = load : () => Promise prop2={result => result} ->prop2 : (result: { success: true; }) => { success: true; } ->result => result : (result: { success: true; }) => { success: true; } ->result : { success: true; } ->result : { success: true; } +>prop2 : (result: not ErrorResult & { success: true; }) => not ErrorResult & { success: true; } +>result => result : (result: not ErrorResult & { success: true; }) => not ErrorResult & { success: true; } +>result : not ErrorResult & { success: true; } +>result : not ErrorResult & { success: true; } />; diff --git a/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.errors.txt b/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.errors.txt index 74835c4a55b2f..d431d6b2c8a7c 100644 --- a/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.errors.txt +++ b/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.errors.txt @@ -2,37 +2,57 @@ tests/cases/compiler/circularlyConstrainedMappedTypeContainingConditionalNoInfin Type 'unknown' is not assignable to type 'Shared>'. Type 'Matching>' is not assignable to type 'Shared>'. Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[P] | (TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[Extract>] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[keyof GetProps & string] | (TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[string] | (TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]) | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[P] | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'GetProps[never] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type '(TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]) | GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] | GetProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type '(TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]) | GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & string] | GetProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. ==== tests/cases/compiler/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.ts (1 errors) ==== @@ -104,35 +124,55 @@ tests/cases/compiler/circularlyConstrainedMappedTypeContainingConditionalNoInfin !!! error TS2344: Type 'unknown' is not assignable to type 'Shared>'. !!! error TS2344: Type 'Matching>' is not assignable to type 'Shared>'. !!! error TS2344: Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[P] | (TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[Extract>] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[keyof GetProps & string] | (TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[string] | (TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]) | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[P] | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'GetProps[never] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]) | GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] | GetProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]) | GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string] | GetProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalTypes1.errors.txt b/tests/baselines/reference/conditionalTypes1.errors.txt index 45d3b1f99cb47..89270b3212418 100644 --- a/tests/baselines/reference/conditionalTypes1.errors.txt +++ b/tests/baselines/reference/conditionalTypes1.errors.txt @@ -36,7 +36,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(117,5): error TS2 tests/cases/conformance/types/conditional/conditionalTypes1.ts(134,10): error TS2540: Cannot assign to 'id' because it is a read-only property. tests/cases/conformance/types/conditional/conditionalTypes1.ts(135,5): error TS2542: Index signature in type 'DeepReadonlyArray' only permits reading. tests/cases/conformance/types/conditional/conditionalTypes1.ts(136,22): error TS2540: Cannot assign to 'id' because it is a read-only property. -tests/cases/conformance/types/conditional/conditionalTypes1.ts(137,10): error TS2339: Property 'updatePart' does not exist on type 'DeepReadonlyObject'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(137,10): error TS2339: Property 'updatePart' does not exist on type 'DeepReadonlyObject'. tests/cases/conformance/types/conditional/conditionalTypes1.ts(159,5): error TS2322: Type 'ZeroOf' is not assignable to type 'T'. 'ZeroOf' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string | number'. Type '0 | (T extends string ? "" : false)' is not assignable to type 'T'. @@ -52,9 +52,15 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(160,5): error TS2 tests/cases/conformance/types/conditional/conditionalTypes1.ts(263,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo'. tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS2322: Type 'T95' is not assignable to type 'T94'. Type 'boolean' is not assignable to type 'true'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(352,12): error TS2322: Type 'number' is not assignable to type '(not any[] & number) | undefined'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(352,18): error TS2322: Type '{ 0: { a: number; c: string; }; }' is not assignable to type '{ [index: number]: RecursivePartial<{ a: number; c: string; }>; }'. + Property '0' is incompatible with index signature. + Type '{ a: number; c: string; }' is not assignable to type 'RecursivePartial<{ a: number; c: string; }>'. + Types of property 'a' are incompatible. + Type 'number' is not assignable to type '(not any[] & number) | undefined'. -==== tests/cases/conformance/types/conditional/conditionalTypes1.ts (22 errors) ==== +==== tests/cases/conformance/types/conditional/conditionalTypes1.ts (24 errors) ==== type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d" type T01 = Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c" @@ -248,7 +254,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS !!! error TS2540: Cannot assign to 'id' because it is a read-only property. part.updatePart("hello"); // Error ~~~~~~~~~~ -!!! error TS2339: Property 'updatePart' does not exist on type 'DeepReadonlyObject'. +!!! error TS2339: Property 'updatePart' does not exist on type 'DeepReadonlyObject'. } type ZeroOf = T extends number ? 0 : T extends string ? "" : false; @@ -484,6 +490,16 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]} assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) + ~ +!!! error TS2322: Type 'number' is not assignable to type '(not any[] & number) | undefined'. +!!! related TS6500 tests/cases/conformance/types/conditional/conditionalTypes1.ts:351:10: The expected type comes from property 'o' which is declared here on type 'RecursivePartial<{ o: number; b: number; c: { a: number; c: string; }[]; }>' + ~ +!!! error TS2322: Type '{ 0: { a: number; c: string; }; }' is not assignable to type '{ [index: number]: RecursivePartial<{ a: number; c: string; }>; }'. +!!! error TS2322: Property '0' is incompatible with index signature. +!!! error TS2322: Type '{ a: number; c: string; }' is not assignable to type 'RecursivePartial<{ a: number; c: string; }>'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type '(not any[] & number) | undefined'. +!!! related TS6500 tests/cases/conformance/types/conditional/conditionalTypes1.ts:351:22: The expected type comes from property 'c' which is declared here on type 'RecursivePartial<{ o: number; b: number; c: { a: number; c: string; }[]; }>' // Repros from #23843 diff --git a/tests/baselines/reference/conditionalTypes1.types b/tests/baselines/reference/conditionalTypes1.types index 234fc071d7433..bfe4d8da0a89c 100644 --- a/tests/baselines/reference/conditionalTypes1.types +++ b/tests/baselines/reference/conditionalTypes1.types @@ -6,7 +6,7 @@ type T01 = Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c" >T01 : "a" | "c" type T02 = Exclude void), Function>; // string | number ->T02 : string | number +>T02 : (not Function & string) | (not Function & number) type T03 = Extract void), Function>; // () => void >T03 : () => void @@ -109,7 +109,7 @@ type Options = { k: "a", a: number } | { k: "b", b: string } | { k: "c", c: bool >c : boolean type T10 = Exclude; // { k: "c", c: boolean } ->T10 : { k: "c"; c: boolean; } +>T10 : not { k: "a" | "b"; } & { k: "c"; c: boolean; } >k : "a" | "b" type T11 = Extract; // { k: "a", a: number } | { k: "b", b: string } @@ -117,7 +117,7 @@ type T11 = Extract; // { k: "a", a: number } | { k: >k : "a" | "b" type T12 = Exclude; // { k: "c", c: boolean } ->T12 : { k: "c"; c: boolean; } +>T12 : not { k: "a"; } & not { k: "b"; } & { k: "c"; c: boolean; } >k : "a" >k : "b" @@ -127,7 +127,7 @@ type T13 = Extract; // { k: "a", a: number } >k : "b" type T14 = Exclude; // Options ->T14 : Options +>T14 : (not { q: "a"; } & { k: "a"; a: number; }) | (not { q: "a"; } & { k: "b"; b: string; }) | (not { q: "a"; } & { k: "c"; c: boolean; }) >q : "a" type T15 = Extract; // never @@ -334,68 +334,68 @@ type DeepReadonlyObject = { }; function f10(part: DeepReadonly) { ->f10 : (part: DeepReadonlyObject) => void ->part : DeepReadonlyObject +>f10 : (part: DeepReadonlyObject) => void +>part : DeepReadonlyObject let name: string = part.name; >name : string ->part.name : string ->part : DeepReadonlyObject ->name : string +>part.name : not any[] & string +>part : DeepReadonlyObject +>name : not any[] & string let id: number = part.subparts[0].id; >id : number ->part.subparts[0].id : number ->part.subparts[0] : DeepReadonlyObject +>part.subparts[0].id : not any[] & number +>part.subparts[0] : DeepReadonlyObject >part.subparts : DeepReadonlyArray ->part : DeepReadonlyObject +>part : DeepReadonlyObject >subparts : DeepReadonlyArray >0 : 0 ->id : number +>id : not any[] & number part.id = part.id; // Error ->part.id = part.id : number +>part.id = part.id : not any[] & number >part.id : any ->part : DeepReadonlyObject +>part : DeepReadonlyObject >id : any ->part.id : number ->part : DeepReadonlyObject ->id : number +>part.id : not any[] & number +>part : DeepReadonlyObject +>id : not any[] & number part.subparts[0] = part.subparts[0]; // Error ->part.subparts[0] = part.subparts[0] : DeepReadonlyObject ->part.subparts[0] : DeepReadonlyObject +>part.subparts[0] = part.subparts[0] : DeepReadonlyObject +>part.subparts[0] : DeepReadonlyObject >part.subparts : DeepReadonlyArray ->part : DeepReadonlyObject +>part : DeepReadonlyObject >subparts : DeepReadonlyArray >0 : 0 ->part.subparts[0] : DeepReadonlyObject +>part.subparts[0] : DeepReadonlyObject >part.subparts : DeepReadonlyArray ->part : DeepReadonlyObject +>part : DeepReadonlyObject >subparts : DeepReadonlyArray >0 : 0 part.subparts[0].id = part.subparts[0].id; // Error ->part.subparts[0].id = part.subparts[0].id : number +>part.subparts[0].id = part.subparts[0].id : not any[] & number >part.subparts[0].id : any ->part.subparts[0] : DeepReadonlyObject +>part.subparts[0] : DeepReadonlyObject >part.subparts : DeepReadonlyArray ->part : DeepReadonlyObject +>part : DeepReadonlyObject >subparts : DeepReadonlyArray >0 : 0 >id : any ->part.subparts[0].id : number ->part.subparts[0] : DeepReadonlyObject +>part.subparts[0].id : not any[] & number +>part.subparts[0] : DeepReadonlyObject >part.subparts : DeepReadonlyArray ->part : DeepReadonlyObject +>part : DeepReadonlyObject >subparts : DeepReadonlyArray >0 : 0 ->id : number +>id : not any[] & number part.updatePart("hello"); // Error >part.updatePart("hello") : any >part.updatePart : any ->part : DeepReadonlyObject +>part : DeepReadonlyObject >updatePart : any >"hello" : "hello" } @@ -1039,7 +1039,7 @@ var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]} >'213' : "213" assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) ->assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) : void +>assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) : any >assign : (o: T, a: RecursivePartial) => void >a : { o: number; b: number; c: { a: number; c: string; }[]; } >{o: 2, c: {0: {a: 2, c: '213123'}}} : { o: number; c: { 0: { a: number; c: string; }; }; } diff --git a/tests/baselines/reference/conditionalTypes2.errors.txt b/tests/baselines/reference/conditionalTypes2.errors.txt index 4093bf46fb0ee..c3d53f7488b37 100644 --- a/tests/baselines/reference/conditionalTypes2.errors.txt +++ b/tests/baselines/reference/conditionalTypes2.errors.txt @@ -20,8 +20,8 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS23 tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. Types of property 'foo' are incompatible. Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'. - Type 'A' is not assignable to type 'B'. - 'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'. + Type 'not string & A' is not assignable to type 'B'. + 'not string & A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'. tests/cases/conformance/types/conditional/conditionalTypes2.ts(73,12): error TS2345: Argument of type 'Extract, Bar>' is not assignable to parameter of type '{ foo: string; bat: string; }'. Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. Type 'Extract' is not assignable to type '{ foo: string; bat: string; }'. @@ -85,8 +85,8 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2 !!! error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. !!! error TS2322: Types of property 'foo' are incompatible. !!! error TS2322: Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'. -!!! error TS2322: Type 'A' is not assignable to type 'B'. -!!! error TS2322: 'A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'. +!!! error TS2322: Type 'not string & A' is not assignable to type 'B'. +!!! error TS2322: 'not string & A' is assignable to the constraint of type 'B', but 'B' could be instantiated with a different subtype of constraint '{}'. } // Extract is a T that is known to be a Function diff --git a/tests/baselines/reference/conditionalTypes2.types b/tests/baselines/reference/conditionalTypes2.types index e3d949f268e90..b6171ae99d14e 100644 --- a/tests/baselines/reference/conditionalTypes2.types +++ b/tests/baselines/reference/conditionalTypes2.types @@ -412,10 +412,10 @@ type ProductComplement = { }; type PCA = ProductComplement['a']; ->PCA : Product<"b", 1> +>PCA : not { f1: "a"; } & Product<"b", 1> type PCB = ProductComplement['b']; ->PCB : Product<"a", 0> +>PCB : not { f1: "b"; } & Product<"a", 0> // {a: Product<'a', 0>; b: Product<'b', 1>} type ProductComplementComplement = { @@ -426,10 +426,10 @@ type ProductComplementComplement = { }; type PCCA = ProductComplementComplement['a']; ->PCCA : Product<"a", 0> +>PCCA : Product<"a", 0> | ({ f1: "a"; } & Product<"b", 1>) type PCCB = ProductComplementComplement['b']; ->PCCB : Product<"b", 1> +>PCCB : Product<"b", 1> | ({ f1: "b"; } & Product<"a", 0>) // Repro from #31326 diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt index 4c29b010295b6..f952fcc91035e 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,19): error TS2345: Argument of type '(a1: (y: string) => string) => (n: Object) => number' is not assignable to parameter of type '(x: (a: string) => boolean) => (n: Object) => number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(32,19): error TS2345: Argument of type '(a1: (y: string) => string) => (n: Object) => number' is not assignable to parameter of type '(x: (a: string) => boolean) => number'. Types of parameters 'a1' and 'x' are incompatible. Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,69): error TS2345: Argument of type '(a2: (z: string) => boolean) => number' is not assignable to parameter of type '(x: (z: string) => boolean) => (n: Object) => number'. - Type 'number' is not assignable to type '(n: Object) => number'. +tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts(33,19): error TS2345: Argument of type '(a1: (y: string) => boolean) => (n: Object) => number' is not assignable to parameter of type '(x: (z: string) => boolean) => number'. + Type '(n: Object) => number' is not assignable to type 'number'. ==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts (2 errors) ==== @@ -39,10 +39,12 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGen var x: (a: string) => boolean; var r11 = foo2(x, (a1: (y: string) => string) => (n: Object) => 1, (a2: (z: string) => string) => 2); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(a1: (y: string) => string) => (n: Object) => number' is not assignable to parameter of type '(x: (a: string) => boolean) => (n: Object) => number'. +!!! error TS2345: Argument of type '(a1: (y: string) => string) => (n: Object) => number' is not assignable to parameter of type '(x: (a: string) => boolean) => number'. !!! error TS2345: Types of parameters 'a1' and 'x' are incompatible. !!! error TS2345: Type 'boolean' is not assignable to type 'string'. +!!! related TS6212 tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts:32:19: Did you mean to call this expression? var r12 = foo2(x, (a1: (y: string) => boolean) => (n: Object) => 1, (a2: (z: string) => boolean) => 2); // error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(a2: (z: string) => boolean) => number' is not assignable to parameter of type '(x: (z: string) => boolean) => (n: Object) => number'. -!!! error TS2345: Type 'number' is not assignable to type '(n: Object) => number'. \ No newline at end of file + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(a1: (y: string) => boolean) => (n: Object) => number' is not assignable to parameter of type '(x: (z: string) => boolean) => number'. +!!! error TS2345: Type '(n: Object) => number' is not assignable to type 'number'. +!!! related TS6212 tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithGenericSignatureArguments3.ts:33:19: Did you mean to call this expression? \ No newline at end of file diff --git a/tests/baselines/reference/genericRestParameters1.errors.txt b/tests/baselines/reference/genericRestParameters1.errors.txt index cd9e799535bdb..7a5e89129cb39 100644 --- a/tests/baselines/reference/genericRestParameters1.errors.txt +++ b/tests/baselines/reference/genericRestParameters1.errors.txt @@ -2,12 +2,14 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(22,11): error TS255 tests/cases/conformance/types/rest/genericRestParameters1.ts(31,11): error TS2556: Expected 3 arguments, but got 1 or more. tests/cases/conformance/types/rest/genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any) => any'. Type 'Function' provides no match for the signature '(...args: any): any'. +tests/cases/conformance/types/rest/genericRestParameters1.ts(151,21): error TS2345: Argument of type '"Bye!"' is not assignable to parameter of type 'not any[] & string'. + Type '"Bye!"' is not assignable to type 'not any[]'. tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS2322: Type '(a: never) => void' is not assignable to type '(...args: any[]) => void'. Types of parameters 'a' and 'args' are incompatible. Type 'any' is not assignable to type 'never'. -==== tests/cases/conformance/types/rest/genericRestParameters1.ts (4 errors) ==== +==== tests/cases/conformance/types/rest/genericRestParameters1.ts (5 errors) ==== declare let f1: (...x: [number, string, boolean]) => void; declare let f2: (x0: number, x1: string, x2: boolean) => void; @@ -167,6 +169,9 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS232 events.emit('move', 10, 'left'); events.emit('jump', 20, 'up'); events.emit('stop', 'Bye!'); + ~~~~~~ +!!! error TS2345: Argument of type '"Bye!"' is not assignable to parameter of type 'not any[] & string'. +!!! error TS2345: Type '"Bye!"' is not assignable to type 'not any[]'. events.emit('done'); // Repro from #25871 diff --git a/tests/baselines/reference/genericRestParameters1.types b/tests/baselines/reference/genericRestParameters1.types index c9067b38c974d..bc5c79ac71e05 100644 --- a/tests/baselines/reference/genericRestParameters1.types +++ b/tests/baselines/reference/genericRestParameters1.types @@ -750,7 +750,7 @@ events.emit('jump', 20, 'up'); >'up' : "up" events.emit('stop', 'Bye!'); ->events.emit('stop', 'Bye!') : void +>events.emit('stop', 'Bye!') : any >events.emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void >events : EventType >emit : (e: K, ...payload: Record1[K] extends any[] ? Record1[K] : [Record1[K]]) => void diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types index 2696b520ae8a4..d989a3e6e2005 100644 --- a/tests/baselines/reference/inferTypes1.types +++ b/tests/baselines/reference/inferTypes1.types @@ -10,7 +10,7 @@ type Unpacked = T; type T00 = Unpacked; // string ->T00 : string +>T00 : not Promise & not ((...args: any[]) => unknown) & not unknown[] & string type T01 = Unpacked; // string >T01 : string @@ -347,25 +347,25 @@ declare class MyClass { } type JsonifiedExample = Jsonified; ->JsonifiedExample : JsonifiedObject +>JsonifiedExample : JsonifiedObject declare let ex: JsonifiedExample; ->ex : JsonifiedObject +>ex : JsonifiedObject const z1: "correct" = ex.customClass; >z1 : "correct" >ex.customClass : "correct" ->ex : JsonifiedObject +>ex : JsonifiedObject >customClass : "correct" const z2: string = ex.obj.nested.attr; >z2 : string >ex.obj.nested.attr : string ->ex.obj.nested : JsonifiedObject<{ attr: Date; }> ->ex.obj : JsonifiedObject<{ prop: "property"; clz: MyClass; nested: { attr: Date; }; }> ->ex : JsonifiedObject ->obj : JsonifiedObject<{ prop: "property"; clz: MyClass; nested: { attr: Date; }; }> ->nested : JsonifiedObject<{ attr: Date; }> +>ex.obj.nested : JsonifiedObject +>ex.obj : JsonifiedObject +>ex : JsonifiedObject +>obj : JsonifiedObject +>nested : JsonifiedObject >attr : string // Repros from #21631 diff --git a/tests/baselines/reference/infiniteConstraints.errors.txt b/tests/baselines/reference/infiniteConstraints.errors.txt index 685b18932c119..d944af54c8acd 100644 --- a/tests/baselines/reference/infiniteConstraints.errors.txt +++ b/tests/baselines/reference/infiniteConstraints.errors.txt @@ -1,13 +1,16 @@ +tests/cases/compiler/infiniteConstraints.ts(3,37): error TS2536: Type '"val"' cannot be used to index type 'Extract], { val: string; }>'. tests/cases/compiler/infiniteConstraints.ts(4,37): error TS2536: Type '"val"' cannot be used to index type 'B[Exclude]'. tests/cases/compiler/infiniteConstraints.ts(31,43): error TS2322: Type 'Record<"val", "dup">' is not assignable to type 'never'. tests/cases/compiler/infiniteConstraints.ts(31,63): error TS2322: Type 'Record<"val", "dup">' is not assignable to type 'never'. tests/cases/compiler/infiniteConstraints.ts(36,71): error TS2536: Type '"foo"' cannot be used to index type 'T[keyof T]'. -==== tests/cases/compiler/infiniteConstraints.ts (4 errors) ==== +==== tests/cases/compiler/infiniteConstraints.ts (5 errors) ==== // Both of the following types trigger the recursion limiter in getImmediateBaseConstraint type T1], { val: string }>["val"] }> = B; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2536: Type '"val"' cannot be used to index type 'Extract], { val: string; }>'. type T2]["val"] }> = B; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2536: Type '"val"' cannot be used to index type 'B[Exclude]'. diff --git a/tests/baselines/reference/instantiateContextualTypes.types b/tests/baselines/reference/instantiateContextualTypes.types index 0e755e82ed308..d353665e1ab85 100644 --- a/tests/baselines/reference/instantiateContextualTypes.types +++ b/tests/baselines/reference/instantiateContextualTypes.types @@ -260,7 +260,7 @@ class InferFunctionTypes extends Component<{children: (foo: number) => string}> >foo : number createElement(InferFunctionTypes, (foo) => "" + foo); ->createElement(InferFunctionTypes, (foo) => "" + foo) : any +>createElement(InferFunctionTypes, (foo) => "" + foo) : error >createElement :

(type: ComponentClass

, ...children: P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown) => any >InferFunctionTypes : typeof InferFunctionTypes >(foo) => "" + foo : (foo: number) => string @@ -270,7 +270,7 @@ createElement(InferFunctionTypes, (foo) => "" + foo); >foo : number createElement2(InferFunctionTypes, [(foo) => "" + foo]); ->createElement2(InferFunctionTypes, [(foo) => "" + foo]) : any +>createElement2(InferFunctionTypes, [(foo) => "" + foo]) : error >createElement2 :

(type: ComponentClass

, child: P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown) => any >InferFunctionTypes : typeof InferFunctionTypes >[(foo) => "" + foo] : ((foo: number) => string)[] diff --git a/tests/baselines/reference/intersectionWithUnionConstraint.types b/tests/baselines/reference/intersectionWithUnionConstraint.types index 0f9e9974bed8d..f4297e1aa1dc7 100644 --- a/tests/baselines/reference/intersectionWithUnionConstraint.types +++ b/tests/baselines/reference/intersectionWithUnionConstraint.types @@ -47,21 +47,21 @@ type T1 = (string | number | undefined) & (string | null | undefined); // strin >null : null function f3(x: T & (number | object | undefined)) { ->f3 : (x: (T & undefined) | (T & number) | (T & object)) => void ->x : (T & undefined) | (T & number) | (T & object) +>f3 : (x: (T & undefined) | (T & number)) => void +>x : (T & undefined) | (T & number) const y: number | undefined = x; >y : number | undefined ->x : (T & undefined) | (T & number) | (T & object) +>x : (T & undefined) | (T & number) } function f4(x: T & (number | object)) { ->f4 : (x: (T & number) | (T & object)) => void ->x : (T & number) | (T & object) +>f4 : (x: T & number) => void +>x : T & number const y: number = x; >y : number ->x : (T & number) | (T & object) +>x : T & number } function f5(x: keyof T & U) { diff --git a/tests/baselines/reference/mappedTypesArraysTuples.types b/tests/baselines/reference/mappedTypesArraysTuples.types index 6b43cd510fb15..4927568a2c0b8 100644 --- a/tests/baselines/reference/mappedTypesArraysTuples.types +++ b/tests/baselines/reference/mappedTypesArraysTuples.types @@ -170,29 +170,29 @@ function f1(a: number, b: Promise, c: string[], d: Promise) { >d : Promise let x1 = all(a); ->x1 : Promise<[number]> ->all(a) : Promise<[number]> +>x1 : Promise<[not PromiseLike & number]> +>all(a) : Promise<[not PromiseLike & number]> >all : (...values: T) => Promise> >a : number let x2 = all(a, b); ->x2 : Promise<[number, number]> ->all(a, b) : Promise<[number, number]> +>x2 : Promise<[not PromiseLike & number, number]> +>all(a, b) : Promise<[not PromiseLike & number, number]> >all : (...values: T) => Promise> >a : number >b : Promise let x3 = all(a, b, c); ->x3 : Promise<[number, number, string[]]> ->all(a, b, c) : Promise<[number, number, string[]]> +>x3 : Promise<[not PromiseLike & number, number, not PromiseLike & string[]]> +>all(a, b, c) : Promise<[not PromiseLike & number, number, not PromiseLike & string[]]> >all : (...values: T) => Promise> >a : number >b : Promise >c : string[] let x4 = all(a, b, c, d); ->x4 : Promise<[number, number, string[], string[]]> ->all(a, b, c, d) : Promise<[number, number, string[], string[]]> +>x4 : Promise<[not PromiseLike & number, number, not PromiseLike & string[], string[]]> +>all(a, b, c, d) : Promise<[not PromiseLike & number, number, not PromiseLike & string[], string[]]> >all : (...values: T) => Promise> >a : number >b : Promise diff --git a/tests/baselines/reference/negatedFreshTreatedAsClosedSet.errors.txt b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.errors.txt new file mode 100644 index 0000000000000..a76779fb4ba3f --- /dev/null +++ b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts(10,4): error TS2345: Argument of type '{ x: number; y: number; }' is not assignable to parameter of type 'Distinct<{ x: any; }, { y: any; }>'. + Type '{ x: number; y: number; }' is not assignable to type '{ y: any; } & not { x: any; }'. + Type '{ x: number; y: number; }' is not assignable to type 'not { x: any; }'. + + +==== tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts (1 errors) ==== + // from https://github.com/Microsoft/TypeScript/issues/4183 + type Distinct = (A | B) & not (A & B); + declare var o1: {x}; + declare var o2: {y}; + + declare function f1(x: Distinct): void; + + f1({x: 0}); // OK + f1({y: 0}); // OK + f1({x: 0, y: 0}); // Should error + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: number; y: number; }' is not assignable to parameter of type 'Distinct<{ x: any; }, { y: any; }>'. +!!! error TS2345: Type '{ x: number; y: number; }' is not assignable to type '{ y: any; } & not { x: any; }'. +!!! error TS2345: Type '{ x: number; y: number; }' is not assignable to type 'not { x: any; }'. + \ No newline at end of file diff --git a/tests/baselines/reference/negatedFreshTreatedAsClosedSet.js b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.js new file mode 100644 index 0000000000000..40598e2dd6447 --- /dev/null +++ b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.js @@ -0,0 +1,17 @@ +//// [negatedFreshTreatedAsClosedSet.ts] +// from https://github.com/Microsoft/TypeScript/issues/4183 +type Distinct = (A | B) & not (A & B); +declare var o1: {x}; +declare var o2: {y}; + +declare function f1(x: Distinct): void; + +f1({x: 0}); // OK +f1({y: 0}); // OK +f1({x: 0, y: 0}); // Should error + + +//// [negatedFreshTreatedAsClosedSet.js] +f1({ x: 0 }); // OK +f1({ y: 0 }); // OK +f1({ x: 0, y: 0 }); // Should error diff --git a/tests/baselines/reference/negatedFreshTreatedAsClosedSet.symbols b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.symbols new file mode 100644 index 0000000000000..7cec3d733aa80 --- /dev/null +++ b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts === +// from https://github.com/Microsoft/TypeScript/issues/4183 +type Distinct = (A | B) & not (A & B); +>Distinct : Symbol(Distinct, Decl(negatedFreshTreatedAsClosedSet.ts, 0, 0)) +>A : Symbol(A, Decl(negatedFreshTreatedAsClosedSet.ts, 1, 14)) +>B : Symbol(B, Decl(negatedFreshTreatedAsClosedSet.ts, 1, 16)) +>A : Symbol(A, Decl(negatedFreshTreatedAsClosedSet.ts, 1, 14)) +>B : Symbol(B, Decl(negatedFreshTreatedAsClosedSet.ts, 1, 16)) +>A : Symbol(A, Decl(negatedFreshTreatedAsClosedSet.ts, 1, 14)) +>B : Symbol(B, Decl(negatedFreshTreatedAsClosedSet.ts, 1, 16)) + +declare var o1: {x}; +>o1 : Symbol(o1, Decl(negatedFreshTreatedAsClosedSet.ts, 2, 11)) +>x : Symbol(x, Decl(negatedFreshTreatedAsClosedSet.ts, 2, 17)) + +declare var o2: {y}; +>o2 : Symbol(o2, Decl(negatedFreshTreatedAsClosedSet.ts, 3, 11)) +>y : Symbol(y, Decl(negatedFreshTreatedAsClosedSet.ts, 3, 17)) + +declare function f1(x: Distinct): void; +>f1 : Symbol(f1, Decl(negatedFreshTreatedAsClosedSet.ts, 3, 20)) +>x : Symbol(x, Decl(negatedFreshTreatedAsClosedSet.ts, 5, 20)) +>Distinct : Symbol(Distinct, Decl(negatedFreshTreatedAsClosedSet.ts, 0, 0)) +>o1 : Symbol(o1, Decl(negatedFreshTreatedAsClosedSet.ts, 2, 11)) +>o2 : Symbol(o2, Decl(negatedFreshTreatedAsClosedSet.ts, 3, 11)) + +f1({x: 0}); // OK +>f1 : Symbol(f1, Decl(negatedFreshTreatedAsClosedSet.ts, 3, 20)) +>x : Symbol(x, Decl(negatedFreshTreatedAsClosedSet.ts, 7, 4)) + +f1({y: 0}); // OK +>f1 : Symbol(f1, Decl(negatedFreshTreatedAsClosedSet.ts, 3, 20)) +>y : Symbol(y, Decl(negatedFreshTreatedAsClosedSet.ts, 8, 4)) + +f1({x: 0, y: 0}); // Should error +>f1 : Symbol(f1, Decl(negatedFreshTreatedAsClosedSet.ts, 3, 20)) +>x : Symbol(x, Decl(negatedFreshTreatedAsClosedSet.ts, 9, 4)) +>y : Symbol(y, Decl(negatedFreshTreatedAsClosedSet.ts, 9, 9)) + diff --git a/tests/baselines/reference/negatedFreshTreatedAsClosedSet.types b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.types new file mode 100644 index 0000000000000..abb93ffbb534c --- /dev/null +++ b/tests/baselines/reference/negatedFreshTreatedAsClosedSet.types @@ -0,0 +1,42 @@ +=== tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts === +// from https://github.com/Microsoft/TypeScript/issues/4183 +type Distinct = (A | B) & not (A & B); +>Distinct : Distinct + +declare var o1: {x}; +>o1 : { x: any; } +>x : any + +declare var o2: {y}; +>o2 : { y: any; } +>y : any + +declare function f1(x: Distinct): void; +>f1 : (x: Distinct<{ x: any; }, { y: any; }>) => void +>x : Distinct<{ x: any; }, { y: any; }> +>o1 : { x: any; } +>o2 : { y: any; } + +f1({x: 0}); // OK +>f1({x: 0}) : void +>f1 : (x: Distinct<{ x: any; }, { y: any; }>) => void +>{x: 0} : { x: number; } +>x : number +>0 : 0 + +f1({y: 0}); // OK +>f1({y: 0}) : void +>f1 : (x: Distinct<{ x: any; }, { y: any; }>) => void +>{y: 0} : { y: number; } +>y : number +>0 : 0 + +f1({x: 0, y: 0}); // Should error +>f1({x: 0, y: 0}) : void +>f1 : (x: Distinct<{ x: any; }, { y: any; }>) => void +>{x: 0, y: 0} : { x: number; y: number; } +>x : number +>0 : 0 +>y : number +>0 : 0 + diff --git a/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.errors.txt b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.errors.txt new file mode 100644 index 0000000000000..5cc99412341a8 --- /dev/null +++ b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts(16,5): error TS2322: Type '{ foo: number; bar: number; other: string; }' is not assignable to type 'Config'. + Object literal may only specify known properties, and 'other' does not exist in type 'Config'. +tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts(22,5): error TS2322: Type '{ foo: number; bar: number; other: number; }' is not assignable to type 'Config'. + Object literal may only specify known properties, and 'other' does not exist in type 'Config'. + + +==== tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts (2 errors) ==== + // https://github.com/Microsoft/TypeScript/issues/4196 + // needs https://github.com/Microsoft/TypeScript/pull/26797 to work, as even though the mapped type can be + // written, the key type `string & ~("foo" | "bar")` can't be represented as properties or string/number index + // signatures + + type Config = { + foo: number; + bar: number; + } & { + [k in (string & not ("foo" | "bar"))]: string; + }; + + const conf: Config = { + foo: 12, + bar: 12, + other: "string" + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ foo: number; bar: number; other: string; }' is not assignable to type 'Config'. +!!! error TS2322: Object literal may only specify known properties, and 'other' does not exist in type 'Config'. + }; // OK + + const conf2: Config = { + foo: 12, + bar: 12, + other: 0, + ~~~~~~~~ +!!! error TS2322: Type '{ foo: number; bar: number; other: number; }' is not assignable to type 'Config'. +!!! error TS2322: Object literal may only specify known properties, and 'other' does not exist in type 'Config'. + }; // Should error + + \ No newline at end of file diff --git a/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.js b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.js new file mode 100644 index 0000000000000..1809626661ce3 --- /dev/null +++ b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.js @@ -0,0 +1,42 @@ +//// [negatedInMappedTypeDisablesExcessProperties.ts] +// https://github.com/Microsoft/TypeScript/issues/4196 +// needs https://github.com/Microsoft/TypeScript/pull/26797 to work, as even though the mapped type can be +// written, the key type `string & ~("foo" | "bar")` can't be represented as properties or string/number index +// signatures + +type Config = { + foo: number; + bar: number; +} & { + [k in (string & not ("foo" | "bar"))]: string; +}; + +const conf: Config = { + foo: 12, + bar: 12, + other: "string" +}; // OK + +const conf2: Config = { + foo: 12, + bar: 12, + other: 0, +}; // Should error + + + +//// [negatedInMappedTypeDisablesExcessProperties.js] +// https://github.com/Microsoft/TypeScript/issues/4196 +// needs https://github.com/Microsoft/TypeScript/pull/26797 to work, as even though the mapped type can be +// written, the key type `string & ~("foo" | "bar")` can't be represented as properties or string/number index +// signatures +var conf = { + foo: 12, + bar: 12, + other: "string" +}; // OK +var conf2 = { + foo: 12, + bar: 12, + other: 0 +}; // Should error diff --git a/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.symbols b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.symbols new file mode 100644 index 0000000000000..3074a744313ef --- /dev/null +++ b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.symbols @@ -0,0 +1,52 @@ +=== tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts === +// https://github.com/Microsoft/TypeScript/issues/4196 +// needs https://github.com/Microsoft/TypeScript/pull/26797 to work, as even though the mapped type can be +// written, the key type `string & ~("foo" | "bar")` can't be represented as properties or string/number index +// signatures + +type Config = { +>Config : Symbol(Config, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 0, 0)) + + foo: number; +>foo : Symbol(foo, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 5, 15)) + + bar: number; +>bar : Symbol(bar, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 6, 16)) + +} & { + [k in (string & not ("foo" | "bar"))]: string; +>k : Symbol(k, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 9, 5)) + +}; + +const conf: Config = { +>conf : Symbol(conf, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 12, 5)) +>Config : Symbol(Config, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 0, 0)) + + foo: 12, +>foo : Symbol(foo, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 12, 22)) + + bar: 12, +>bar : Symbol(bar, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 13, 12)) + + other: "string" +>other : Symbol(other, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 14, 12)) + +}; // OK + +const conf2: Config = { +>conf2 : Symbol(conf2, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 18, 5)) +>Config : Symbol(Config, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 0, 0)) + + foo: 12, +>foo : Symbol(foo, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 18, 23)) + + bar: 12, +>bar : Symbol(bar, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 19, 12)) + + other: 0, +>other : Symbol(other, Decl(negatedInMappedTypeDisablesExcessProperties.ts, 20, 12)) + +}; // Should error + + diff --git a/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.types b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.types new file mode 100644 index 0000000000000..afdb42fef0acf --- /dev/null +++ b/tests/baselines/reference/negatedInMappedTypeDisablesExcessProperties.types @@ -0,0 +1,56 @@ +=== tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts === +// https://github.com/Microsoft/TypeScript/issues/4196 +// needs https://github.com/Microsoft/TypeScript/pull/26797 to work, as even though the mapped type can be +// written, the key type `string & ~("foo" | "bar")` can't be represented as properties or string/number index +// signatures + +type Config = { +>Config : Config + + foo: number; +>foo : number + + bar: number; +>bar : number + +} & { + [k in (string & not ("foo" | "bar"))]: string; +}; + +const conf: Config = { +>conf : Config +>{ foo: 12, bar: 12, other: "string"} : { foo: number; bar: number; other: string; } + + foo: 12, +>foo : number +>12 : 12 + + bar: 12, +>bar : number +>12 : 12 + + other: "string" +>other : string +>"string" : "string" + +}; // OK + +const conf2: Config = { +>conf2 : Config +>{ foo: 12, bar: 12, other: 0,} : { foo: number; bar: number; other: number; } + + foo: 12, +>foo : number +>12 : 12 + + bar: 12, +>bar : number +>12 : 12 + + other: 0, +>other : number +>0 : 0 + +}; // Should error + + diff --git a/tests/baselines/reference/negatedPromiseRepr.js b/tests/baselines/reference/negatedPromiseRepr.js new file mode 100644 index 0000000000000..8433f57930930 --- /dev/null +++ b/tests/baselines/reference/negatedPromiseRepr.js @@ -0,0 +1,62 @@ +//// [negatedPromiseRepr.ts] +// inspired by a comment in https://github.com/Microsoft/TypeScript/issues/4196 + +type AnyPromiseLikeObject = object & MyPromiseLike; +interface MyPromiseLike { + then(onResolve: (value: T) => any, onReject: (error: E) => any): any; +} + +type AwaitValue = T extends MyPromiseLike ? U : T; + +type CoercePromiseLike = MyPromise ? AwaitValue : T, never>; + +interface MyPromiseConstructor { + resolve(value: T): CoercePromiseLike; + reject(value: E): MyPromise; + all(values: Iterable): MyPromise[] & not AnyPromiseLikeObject, E>; + race(values: Iterable): MyPromise, E>; +} +declare var MyPromise: MyPromiseConstructor; + +interface MyPromise { + then(onResolve?: not Function, onReject?: not Function): MyPromise; + catch(onReject?: not Function): MyPromise; + then( + onResolve: (value: AwaitValue) => U, + onReject?: not Function, + ): MyPromise, E | F>; + then( + onResolve: not Function, + onReject: (error: E) => U, + ): MyPromise, F>; + then( + onResolve: (value: AwaitValue) => U, + onReject: (error: E) => AwaitValue, + ): MyPromise, F>; + catch( + onReject: (error: E) => U, + ): MyPromise, F>; + finally(onSettled: () => AnyPromiseLikeObject): MyPromise; +} + +const a = MyPromise.resolve(0); + +const b = MyPromise.resolve(MyPromise.resolve(0)); + +const d = MyPromise.resolve(MyPromise.resolve(MyPromise.resolve(0))); + +const e = MyPromise.resolve(0).then(x => "ok"); + +const f = MyPromise.all([1, 2, 3, Promise.resolve("ok")]); + +const g = MyPromise.race([1, 2, 3, Promise.resolve("ok")]); + + +//// [negatedPromiseRepr.js] +// inspired by a comment in https://github.com/Microsoft/TypeScript/issues/4196 +const a = MyPromise.resolve(0); +const b = MyPromise.resolve(MyPromise.resolve(0)); +const d = MyPromise.resolve(MyPromise.resolve(MyPromise.resolve(0))); +const e = MyPromise.resolve(0).then(x => "ok"); +const f = MyPromise.all([1, 2, 3, Promise.resolve("ok")]); +const g = MyPromise.race([1, 2, 3, Promise.resolve("ok")]); diff --git a/tests/baselines/reference/negatedPromiseRepr.symbols b/tests/baselines/reference/negatedPromiseRepr.symbols new file mode 100644 index 0000000000000..c17d7ea4d6905 --- /dev/null +++ b/tests/baselines/reference/negatedPromiseRepr.symbols @@ -0,0 +1,281 @@ +=== tests/cases/conformance/types/negated/negatedPromiseRepr.ts === +// inspired by a comment in https://github.com/Microsoft/TypeScript/issues/4196 + +type AnyPromiseLikeObject = object & MyPromiseLike; +>AnyPromiseLikeObject : Symbol(AnyPromiseLikeObject, Decl(negatedPromiseRepr.ts, 0, 0)) +>MyPromiseLike : Symbol(MyPromiseLike, Decl(negatedPromiseRepr.ts, 2, 61)) + +interface MyPromiseLike { +>MyPromiseLike : Symbol(MyPromiseLike, Decl(negatedPromiseRepr.ts, 2, 61)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 3, 24)) +>AnyPromiseLikeObject : Symbol(AnyPromiseLikeObject, Decl(negatedPromiseRepr.ts, 0, 0)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 3, 59)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + then(onResolve: (value: T) => any, onReject: (error: E) => any): any; +>then : Symbol(MyPromiseLike.then, Decl(negatedPromiseRepr.ts, 3, 72)) +>onResolve : Symbol(onResolve, Decl(negatedPromiseRepr.ts, 4, 6)) +>value : Symbol(value, Decl(negatedPromiseRepr.ts, 4, 18)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 3, 24)) +>onReject : Symbol(onReject, Decl(negatedPromiseRepr.ts, 4, 35)) +>error : Symbol(error, Decl(negatedPromiseRepr.ts, 4, 47)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 3, 59)) +} + +type AwaitValue = T extends MyPromiseLike ? U : T; +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 7, 16)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 7, 18)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 7, 16)) +>MyPromiseLike : Symbol(MyPromiseLike, Decl(negatedPromiseRepr.ts, 2, 61)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 7, 59)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 7, 18)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 7, 59)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 7, 16)) + +type CoercePromiseLike = MyPromise ? AwaitValue : T, never>; +>CoercePromiseLike : Symbol(CoercePromiseLike, Decl(negatedPromiseRepr.ts, 7, 74)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 9, 23)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 9, 23)) +>MyPromiseLike : Symbol(MyPromiseLike, Decl(negatedPromiseRepr.ts, 2, 61)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 9, 23)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 9, 23)) + +interface MyPromiseConstructor { +>MyPromiseConstructor : Symbol(MyPromiseConstructor, Decl(negatedPromiseRepr.ts, 9, 100)) + + resolve(value: T): CoercePromiseLike; +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 12, 9)) +>value : Symbol(value, Decl(negatedPromiseRepr.ts, 12, 12)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 12, 9)) +>CoercePromiseLike : Symbol(CoercePromiseLike, Decl(negatedPromiseRepr.ts, 7, 74)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 12, 9)) + + reject(value: E): MyPromise; +>reject : Symbol(MyPromiseConstructor.reject, Decl(negatedPromiseRepr.ts, 12, 44)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 13, 8)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(negatedPromiseRepr.ts, 13, 19)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 13, 8)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 13, 8)) + + all(values: Iterable): MyPromise[] & not AnyPromiseLikeObject, E>; +>all : Symbol(MyPromiseConstructor.all, Decl(negatedPromiseRepr.ts, 13, 50)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 14, 5)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 14, 7)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>values : Symbol(values, Decl(negatedPromiseRepr.ts, 14, 19)) +>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 14, 5)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 14, 5)) +>AnyPromiseLikeObject : Symbol(AnyPromiseLikeObject, Decl(negatedPromiseRepr.ts, 0, 0)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 14, 7)) + + race(values: Iterable): MyPromise, E>; +>race : Symbol(MyPromiseConstructor.race, Decl(negatedPromiseRepr.ts, 14, 98)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 15, 6)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 15, 8)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>values : Symbol(values, Decl(negatedPromiseRepr.ts, 15, 20)) +>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 15, 6)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 15, 6)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 15, 8)) +} +declare var MyPromise: MyPromiseConstructor; +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>MyPromiseConstructor : Symbol(MyPromiseConstructor, Decl(negatedPromiseRepr.ts, 9, 100)) + +interface MyPromise { +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>AnyPromiseLikeObject : Symbol(AnyPromiseLikeObject, Decl(negatedPromiseRepr.ts, 0, 0)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + + then(onResolve?: not Function, onReject?: not Function): MyPromise; +>then : Symbol(MyPromise.then, Decl(negatedPromiseRepr.ts, 19, 68), Decl(negatedPromiseRepr.ts, 21, 49), Decl(negatedPromiseRepr.ts, 25, 39), Decl(negatedPromiseRepr.ts, 29, 39)) +>onResolve : Symbol(onResolve, Decl(negatedPromiseRepr.ts, 20, 6)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>onReject : Symbol(onReject, Decl(negatedPromiseRepr.ts, 20, 31)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) + + catch(onReject?: not Function): MyPromise; +>catch : Symbol(MyPromise.catch, Decl(negatedPromiseRepr.ts, 20, 74), Decl(negatedPromiseRepr.ts, 33, 35)) +>onReject : Symbol(onReject, Decl(negatedPromiseRepr.ts, 21, 7)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) + + then( +>then : Symbol(MyPromise.then, Decl(negatedPromiseRepr.ts, 19, 68), Decl(negatedPromiseRepr.ts, 21, 49), Decl(negatedPromiseRepr.ts, 25, 39), Decl(negatedPromiseRepr.ts, 29, 39)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 22, 6)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 22, 8)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) + + onResolve: (value: AwaitValue) => U, +>onResolve : Symbol(onResolve, Decl(negatedPromiseRepr.ts, 22, 16)) +>value : Symbol(value, Decl(negatedPromiseRepr.ts, 23, 14)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 22, 6)) + + onReject?: not Function, +>onReject : Symbol(onReject, Decl(negatedPromiseRepr.ts, 23, 41)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + + ): MyPromise, E | F>; +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 22, 6)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 22, 8)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 22, 8)) + + then( +>then : Symbol(MyPromise.then, Decl(negatedPromiseRepr.ts, 19, 68), Decl(negatedPromiseRepr.ts, 21, 49), Decl(negatedPromiseRepr.ts, 25, 39), Decl(negatedPromiseRepr.ts, 29, 39)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 26, 6)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 26, 8)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) + + onResolve: not Function, +>onResolve : Symbol(onResolve, Decl(negatedPromiseRepr.ts, 26, 16)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + + onReject: (error: E) => U, +>onReject : Symbol(onReject, Decl(negatedPromiseRepr.ts, 27, 26)) +>error : Symbol(error, Decl(negatedPromiseRepr.ts, 28, 13)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 26, 6)) + + ): MyPromise, F>; +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 26, 6)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 26, 8)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 26, 8)) + + then( +>then : Symbol(MyPromise.then, Decl(negatedPromiseRepr.ts, 19, 68), Decl(negatedPromiseRepr.ts, 21, 49), Decl(negatedPromiseRepr.ts, 25, 39), Decl(negatedPromiseRepr.ts, 29, 39)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 30, 6)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 30, 8)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) + + onResolve: (value: AwaitValue) => U, +>onResolve : Symbol(onResolve, Decl(negatedPromiseRepr.ts, 30, 16)) +>value : Symbol(value, Decl(negatedPromiseRepr.ts, 31, 14)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 30, 6)) + + onReject: (error: E) => AwaitValue, +>onReject : Symbol(onReject, Decl(negatedPromiseRepr.ts, 31, 41)) +>error : Symbol(error, Decl(negatedPromiseRepr.ts, 32, 13)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 30, 6)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 30, 8)) + + ): MyPromise, F>; +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 30, 6)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 30, 8)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 30, 8)) + + catch( +>catch : Symbol(MyPromise.catch, Decl(negatedPromiseRepr.ts, 20, 74), Decl(negatedPromiseRepr.ts, 33, 35)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 34, 7)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 34, 9)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) + + onReject: (error: E) => U, +>onReject : Symbol(onReject, Decl(negatedPromiseRepr.ts, 34, 17)) +>error : Symbol(error, Decl(negatedPromiseRepr.ts, 35, 13)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 34, 7)) + + ): MyPromise, F>; +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>AwaitValue : Symbol(AwaitValue, Decl(negatedPromiseRepr.ts, 5, 1)) +>U : Symbol(U, Decl(negatedPromiseRepr.ts, 34, 7)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 34, 9)) +>F : Symbol(F, Decl(negatedPromiseRepr.ts, 34, 9)) + + finally(onSettled: () => AnyPromiseLikeObject): MyPromise; +>finally : Symbol(MyPromise.finally, Decl(negatedPromiseRepr.ts, 36, 39)) +>onSettled : Symbol(onSettled, Decl(negatedPromiseRepr.ts, 37, 9)) +>AnyPromiseLikeObject : Symbol(AnyPromiseLikeObject, Decl(negatedPromiseRepr.ts, 0, 0)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>T : Symbol(T, Decl(negatedPromiseRepr.ts, 19, 20)) +>E : Symbol(E, Decl(negatedPromiseRepr.ts, 19, 55)) +} + +const a = MyPromise.resolve(0); +>a : Symbol(a, Decl(negatedPromiseRepr.ts, 40, 5)) +>MyPromise.resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) + +const b = MyPromise.resolve(MyPromise.resolve(0)); +>b : Symbol(b, Decl(negatedPromiseRepr.ts, 42, 5)) +>MyPromise.resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise.resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) + +const d = MyPromise.resolve(MyPromise.resolve(MyPromise.resolve(0))); +>d : Symbol(d, Decl(negatedPromiseRepr.ts, 44, 5)) +>MyPromise.resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise.resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise.resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) + +const e = MyPromise.resolve(0).then(x => "ok"); +>e : Symbol(e, Decl(negatedPromiseRepr.ts, 46, 5)) +>MyPromise.resolve(0).then : Symbol(MyPromise.then, Decl(negatedPromiseRepr.ts, 19, 68), Decl(negatedPromiseRepr.ts, 21, 49), Decl(negatedPromiseRepr.ts, 25, 39), Decl(negatedPromiseRepr.ts, 29, 39)) +>MyPromise.resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>resolve : Symbol(MyPromiseConstructor.resolve, Decl(negatedPromiseRepr.ts, 11, 32)) +>then : Symbol(MyPromise.then, Decl(negatedPromiseRepr.ts, 19, 68), Decl(negatedPromiseRepr.ts, 21, 49), Decl(negatedPromiseRepr.ts, 25, 39), Decl(negatedPromiseRepr.ts, 29, 39)) +>x : Symbol(x, Decl(negatedPromiseRepr.ts, 46, 36)) + +const f = MyPromise.all([1, 2, 3, Promise.resolve("ok")]); +>f : Symbol(f, Decl(negatedPromiseRepr.ts, 48, 5)) +>MyPromise.all : Symbol(MyPromiseConstructor.all, Decl(negatedPromiseRepr.ts, 13, 50)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>all : Symbol(MyPromiseConstructor.all, Decl(negatedPromiseRepr.ts, 13, 50)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +const g = MyPromise.race([1, 2, 3, Promise.resolve("ok")]); +>g : Symbol(g, Decl(negatedPromiseRepr.ts, 50, 5)) +>MyPromise.race : Symbol(MyPromiseConstructor.race, Decl(negatedPromiseRepr.ts, 14, 98)) +>MyPromise : Symbol(MyPromise, Decl(negatedPromiseRepr.ts, 17, 11), Decl(negatedPromiseRepr.ts, 17, 44)) +>race : Symbol(MyPromiseConstructor.race, Decl(negatedPromiseRepr.ts, 14, 98)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + diff --git a/tests/baselines/reference/negatedPromiseRepr.types b/tests/baselines/reference/negatedPromiseRepr.types new file mode 100644 index 0000000000000..2769cb475393c --- /dev/null +++ b/tests/baselines/reference/negatedPromiseRepr.types @@ -0,0 +1,180 @@ +=== tests/cases/conformance/types/negated/negatedPromiseRepr.ts === +// inspired by a comment in https://github.com/Microsoft/TypeScript/issues/4196 + +type AnyPromiseLikeObject = object & MyPromiseLike; +>AnyPromiseLikeObject : AnyPromiseLikeObject + +interface MyPromiseLike { + then(onResolve: (value: T) => any, onReject: (error: E) => any): any; +>then : (onResolve: (value: T) => any, onReject: (error: E) => any) => any +>onResolve : (value: T) => any +>value : T +>onReject : (error: E) => any +>error : E +} + +type AwaitValue = T extends MyPromiseLike ? U : T; +>AwaitValue : AwaitValue + +type CoercePromiseLike = MyPromise ? AwaitValue : T, never>; +>CoercePromiseLike : MyPromise ? AwaitValue : T, never> + +interface MyPromiseConstructor { + resolve(value: T): CoercePromiseLike; +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>value : T + + reject(value: E): MyPromise; +>reject : (value: E) => MyPromise +>value : E + + all(values: Iterable): MyPromise[] & not AnyPromiseLikeObject, E>; +>all : (values: Iterable) => MyPromise[] & not MyPromiseLike, E> +>values : Iterable + + race(values: Iterable): MyPromise, E>; +>race : (values: Iterable) => MyPromise, E> +>values : Iterable +} +declare var MyPromise: MyPromiseConstructor; +>MyPromise : MyPromiseConstructor + +interface MyPromise { + then(onResolve?: not Function, onReject?: not Function): MyPromise; +>then : { (onResolve?: not Function, onReject?: not Function): MyPromise; (onResolve: (value: AwaitValue) => U, onReject?: not Function): MyPromise, E | F>; (onResolve: not Function, onReject: (error: E) => U): MyPromise, F>; (onResolve: (value: AwaitValue) => U, onReject: (error: E) => AwaitValue): MyPromise, F>; } +>onResolve : not Function +>onReject : not Function + + catch(onReject?: not Function): MyPromise; +>catch : { (onReject?: not Function): MyPromise; (onReject: (error: E) => U): MyPromise, F>; } +>onReject : not Function + + then( +>then : { (onResolve?: not Function, onReject?: not Function): MyPromise; (onResolve: (value: AwaitValue) => U, onReject?: not Function): MyPromise, E | F>; (onResolve: not Function, onReject: (error: E) => U): MyPromise, F>; (onResolve: (value: AwaitValue) => U, onReject: (error: E) => AwaitValue): MyPromise, F>; } + + onResolve: (value: AwaitValue) => U, +>onResolve : (value: AwaitValue) => U +>value : AwaitValue + + onReject?: not Function, +>onReject : not Function + + ): MyPromise, E | F>; + then( +>then : { (onResolve?: not Function, onReject?: not Function): MyPromise; (onResolve: (value: AwaitValue) => U, onReject?: not Function): MyPromise, E | F>; (onResolve: not Function, onReject: (error: E) => U): MyPromise, F>; (onResolve: (value: AwaitValue) => U, onReject: (error: E) => AwaitValue): MyPromise, F>; } + + onResolve: not Function, +>onResolve : not Function + + onReject: (error: E) => U, +>onReject : (error: E) => U +>error : E + + ): MyPromise, F>; + then( +>then : { (onResolve?: not Function, onReject?: not Function): MyPromise; (onResolve: (value: AwaitValue) => U, onReject?: not Function): MyPromise, E | F>; (onResolve: not Function, onReject: (error: E) => U): MyPromise, F>; (onResolve: (value: AwaitValue) => U, onReject: (error: E) => AwaitValue): MyPromise, F>; } + + onResolve: (value: AwaitValue) => U, +>onResolve : (value: AwaitValue) => U +>value : AwaitValue + + onReject: (error: E) => AwaitValue, +>onReject : (error: E) => AwaitValue +>error : E + + ): MyPromise, F>; + catch( +>catch : { (onReject?: not Function): MyPromise; (onReject: (error: E) => U): MyPromise, F>; } + + onReject: (error: E) => U, +>onReject : (error: E) => U +>error : E + + ): MyPromise, F>; + finally(onSettled: () => AnyPromiseLikeObject): MyPromise; +>finally : (onSettled: () => AnyPromiseLikeObject) => MyPromise +>onSettled : () => AnyPromiseLikeObject +} + +const a = MyPromise.resolve(0); +>a : MyPromise & number, never> +>MyPromise.resolve(0) : MyPromise & number, never> +>MyPromise.resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise : MyPromiseConstructor +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>0 : 0 + +const b = MyPromise.resolve(MyPromise.resolve(0)); +>b : MyPromise & number, never> +>MyPromise.resolve(MyPromise.resolve(0)) : MyPromise & number, never> +>MyPromise.resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise : MyPromiseConstructor +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise.resolve(0) : MyPromise & number, never> +>MyPromise.resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise : MyPromiseConstructor +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>0 : 0 + +const d = MyPromise.resolve(MyPromise.resolve(MyPromise.resolve(0))); +>d : MyPromise & number, never> +>MyPromise.resolve(MyPromise.resolve(MyPromise.resolve(0))) : MyPromise & number, never> +>MyPromise.resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise : MyPromiseConstructor +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise.resolve(MyPromise.resolve(0)) : MyPromise & number, never> +>MyPromise.resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise : MyPromiseConstructor +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise.resolve(0) : MyPromise & number, never> +>MyPromise.resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise : MyPromiseConstructor +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>0 : 0 + +const e = MyPromise.resolve(0).then(x => "ok"); +>e : MyPromise, never> & string, never> +>MyPromise.resolve(0).then(x => "ok") : MyPromise, never> & string, never> +>MyPromise.resolve(0).then : { (onResolve?: not Function, onReject?: not Function): MyPromise & number, never>; (onResolve: (value: not MyPromiseLike & number) => U, onReject?: not Function): MyPromise, F>; (onResolve: not Function, onReject: (error: never) => U): MyPromise<(not MyPromiseLike & number) | AwaitValue, F>; (onResolve: (value: not MyPromiseLike & number) => U, onReject: (error: never) => AwaitValue): MyPromise, F>; } +>MyPromise.resolve(0) : MyPromise & number, never> +>MyPromise.resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>MyPromise : MyPromiseConstructor +>resolve : (value: T) => MyPromise ? AwaitValue : T, never> +>0 : 0 +>then : { (onResolve?: not Function, onReject?: not Function): MyPromise & number, never>; (onResolve: (value: not MyPromiseLike & number) => U, onReject?: not Function): MyPromise, F>; (onResolve: not Function, onReject: (error: never) => U): MyPromise<(not MyPromiseLike & number) | AwaitValue, F>; (onResolve: (value: not MyPromiseLike & number) => U, onReject: (error: never) => AwaitValue): MyPromise, F>; } +>x => "ok" : (x: not MyPromiseLike & number) => string +>x : not MyPromiseLike & number +>"ok" : "ok" + +const f = MyPromise.all([1, 2, 3, Promise.resolve("ok")]); +>f : MyPromise<(string | (not MyPromiseLike, any> & number))[] & not MyPromiseLike, Error> +>MyPromise.all([1, 2, 3, Promise.resolve("ok")]) : MyPromise<(string | (not MyPromiseLike, any> & number))[] & not MyPromiseLike, Error> +>MyPromise.all : (values: Iterable) => MyPromise[] & not MyPromiseLike, E> +>MyPromise : MyPromiseConstructor +>all : (values: Iterable) => MyPromise[] & not MyPromiseLike, E> +>[1, 2, 3, Promise.resolve("ok")] : (number | Promise)[] +>1 : 1 +>2 : 2 +>3 : 3 +>Promise.resolve("ok") : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>"ok" : "ok" + +const g = MyPromise.race([1, 2, 3, Promise.resolve("ok")]); +>g : MyPromise, any> & number), Error> +>MyPromise.race([1, 2, 3, Promise.resolve("ok")]) : MyPromise, any> & number), Error> +>MyPromise.race : (values: Iterable) => MyPromise, E> +>MyPromise : MyPromiseConstructor +>race : (values: Iterable) => MyPromise, E> +>[1, 2, 3, Promise.resolve("ok")] : (number | Promise)[] +>1 : 1 +>2 : 2 +>3 : 3 +>Promise.resolve("ok") : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>"ok" : "ok" + diff --git a/tests/baselines/reference/negatedRepresentativeExamples.errors.txt b/tests/baselines/reference/negatedRepresentativeExamples.errors.txt new file mode 100644 index 0000000000000..eb051d492ae97 --- /dev/null +++ b/tests/baselines/reference/negatedRepresentativeExamples.errors.txt @@ -0,0 +1,61 @@ +tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts(7,8): error TS2345: Argument of type 'Promise' is not assignable to parameter of type 'not object | not Promise'. + Type 'Promise' is not assignable to type 'not Promise'. +tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts(14,16): error TS2345: Argument of type '() => void' is not assignable to parameter of type '(value: number) => not void'. + Type 'void' is not assignable to type 'not void'. +tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts(23,9): error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'not null'. + Type 'null' is not assignable to type 'not null'. +tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts(23,12): error TS7006: Parameter 'n' implicitly has an 'any' type. +tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts(32,7): error TS2345: Argument of type '(number | undefined)[]' is not assignable to parameter of type '(not undefined)[]'. + Type 'number | undefined' is not assignable to type 'not undefined'. + Type 'undefined' is not assignable to type 'not undefined'. + + +==== tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts (5 errors) ==== + // https://github.com/Microsoft/TypeScript/issues/7993 + + declare function ignore)>(value: T): void; + declare function readFileAsync(): Promise; + declare function readFileSync(): string; + ignore(readFileSync()); // OK + ignore(readFileAsync()); // Should error + ~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type 'Promise' is not assignable to parameter of type 'not object | not Promise'. +!!! error TS2345: Type 'Promise' is not assignable to type 'not Promise'. + + declare function map(values: T[], map: (value: T) => U) : U[]; // validate map callback doesn't return void + + function foo() {} + + map([1, 2, 3], n => n + 1); // OK + map([1, 2, 3], foo); // Should error + ~~~ +!!! error TS2345: Argument of type '() => void' is not assignable to parameter of type '(value: number) => not void'. +!!! error TS2345: Type 'void' is not assignable to type 'not void'. + + function asValid(value: T, isValid: (value: T) => boolean) : T | null { + return isValid(value) ? value : null; + } + + declare const x: number; + declare const y: number | null; + asValid(x, n => n >= 0); // OK + asValid(y, n => n >= 0); // Should error + ~ +!!! error TS2345: Argument of type 'number | null' is not assignable to parameter of type 'not null'. +!!! error TS2345: Type 'null' is not assignable to type 'not null'. + ~ +!!! error TS7006: Parameter 'n' implicitly has an 'any' type. + + function tryAt(values: T[], index: number): T | undefined { + return values[index]; + } + + declare const a: number[]; + declare const b: (number | undefined)[]; + tryAt(a, 0); // OK + tryAt(b, 0); // Should error + ~ +!!! error TS2345: Argument of type '(number | undefined)[]' is not assignable to parameter of type '(not undefined)[]'. +!!! error TS2345: Type 'number | undefined' is not assignable to type 'not undefined'. +!!! error TS2345: Type 'undefined' is not assignable to type 'not undefined'. + \ No newline at end of file diff --git a/tests/baselines/reference/negatedRepresentativeExamples.js b/tests/baselines/reference/negatedRepresentativeExamples.js new file mode 100644 index 0000000000000..9336af043da40 --- /dev/null +++ b/tests/baselines/reference/negatedRepresentativeExamples.js @@ -0,0 +1,53 @@ +//// [negatedRepresentativeExamples.ts] +// https://github.com/Microsoft/TypeScript/issues/7993 + +declare function ignore)>(value: T): void; +declare function readFileAsync(): Promise; +declare function readFileSync(): string; +ignore(readFileSync()); // OK +ignore(readFileAsync()); // Should error + +declare function map(values: T[], map: (value: T) => U) : U[]; // validate map callback doesn't return void + +function foo() {} + +map([1, 2, 3], n => n + 1); // OK +map([1, 2, 3], foo); // Should error + +function asValid(value: T, isValid: (value: T) => boolean) : T | null { + return isValid(value) ? value : null; +} + +declare const x: number; +declare const y: number | null; +asValid(x, n => n >= 0); // OK +asValid(y, n => n >= 0); // Should error + +function tryAt(values: T[], index: number): T | undefined { + return values[index]; +} + +declare const a: number[]; +declare const b: (number | undefined)[]; +tryAt(a, 0); // OK +tryAt(b, 0); // Should error + + +//// [negatedRepresentativeExamples.js] +"use strict"; +// https://github.com/Microsoft/TypeScript/issues/7993 +ignore(readFileSync()); // OK +ignore(readFileAsync()); // Should error +function foo() { } +map([1, 2, 3], function (n) { return n + 1; }); // OK +map([1, 2, 3], foo); // Should error +function asValid(value, isValid) { + return isValid(value) ? value : null; +} +asValid(x, function (n) { return n >= 0; }); // OK +asValid(y, function (n) { return n >= 0; }); // Should error +function tryAt(values, index) { + return values[index]; +} +tryAt(a, 0); // OK +tryAt(b, 0); // Should error diff --git a/tests/baselines/reference/negatedRepresentativeExamples.symbols b/tests/baselines/reference/negatedRepresentativeExamples.symbols new file mode 100644 index 0000000000000..04c8a5ac2ac65 --- /dev/null +++ b/tests/baselines/reference/negatedRepresentativeExamples.symbols @@ -0,0 +1,110 @@ +=== tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts === +// https://github.com/Microsoft/TypeScript/issues/7993 + +declare function ignore)>(value: T): void; +>ignore : Symbol(ignore, Decl(negatedRepresentativeExamples.ts, 0, 0)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 2, 24)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(negatedRepresentativeExamples.ts, 2, 63)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 2, 24)) + +declare function readFileAsync(): Promise; +>readFileAsync : Symbol(readFileAsync, Decl(negatedRepresentativeExamples.ts, 2, 79)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) + +declare function readFileSync(): string; +>readFileSync : Symbol(readFileSync, Decl(negatedRepresentativeExamples.ts, 3, 50)) + +ignore(readFileSync()); // OK +>ignore : Symbol(ignore, Decl(negatedRepresentativeExamples.ts, 0, 0)) +>readFileSync : Symbol(readFileSync, Decl(negatedRepresentativeExamples.ts, 3, 50)) + +ignore(readFileAsync()); // Should error +>ignore : Symbol(ignore, Decl(negatedRepresentativeExamples.ts, 0, 0)) +>readFileAsync : Symbol(readFileAsync, Decl(negatedRepresentativeExamples.ts, 2, 79)) + +declare function map(values: T[], map: (value: T) => U) : U[]; // validate map callback doesn't return void +>map : Symbol(map, Decl(negatedRepresentativeExamples.ts, 6, 24)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 8, 21)) +>U : Symbol(U, Decl(negatedRepresentativeExamples.ts, 8, 23)) +>values : Symbol(values, Decl(negatedRepresentativeExamples.ts, 8, 44)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 8, 21)) +>map : Symbol(map, Decl(negatedRepresentativeExamples.ts, 8, 56)) +>value : Symbol(value, Decl(negatedRepresentativeExamples.ts, 8, 63)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 8, 21)) +>U : Symbol(U, Decl(negatedRepresentativeExamples.ts, 8, 23)) +>U : Symbol(U, Decl(negatedRepresentativeExamples.ts, 8, 23)) + +function foo() {} +>foo : Symbol(foo, Decl(negatedRepresentativeExamples.ts, 8, 85)) + +map([1, 2, 3], n => n + 1); // OK +>map : Symbol(map, Decl(negatedRepresentativeExamples.ts, 6, 24)) +>n : Symbol(n, Decl(negatedRepresentativeExamples.ts, 12, 14)) +>n : Symbol(n, Decl(negatedRepresentativeExamples.ts, 12, 14)) + +map([1, 2, 3], foo); // Should error +>map : Symbol(map, Decl(negatedRepresentativeExamples.ts, 6, 24)) +>foo : Symbol(foo, Decl(negatedRepresentativeExamples.ts, 8, 85)) + +function asValid(value: T, isValid: (value: T) => boolean) : T | null { +>asValid : Symbol(asValid, Decl(negatedRepresentativeExamples.ts, 13, 20)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 15, 17)) +>value : Symbol(value, Decl(negatedRepresentativeExamples.ts, 15, 37)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 15, 17)) +>isValid : Symbol(isValid, Decl(negatedRepresentativeExamples.ts, 15, 46)) +>value : Symbol(value, Decl(negatedRepresentativeExamples.ts, 15, 57)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 15, 17)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 15, 17)) + + return isValid(value) ? value : null; +>isValid : Symbol(isValid, Decl(negatedRepresentativeExamples.ts, 15, 46)) +>value : Symbol(value, Decl(negatedRepresentativeExamples.ts, 15, 37)) +>value : Symbol(value, Decl(negatedRepresentativeExamples.ts, 15, 37)) +} + +declare const x: number; +>x : Symbol(x, Decl(negatedRepresentativeExamples.ts, 19, 13)) + +declare const y: number | null; +>y : Symbol(y, Decl(negatedRepresentativeExamples.ts, 20, 13)) + +asValid(x, n => n >= 0); // OK +>asValid : Symbol(asValid, Decl(negatedRepresentativeExamples.ts, 13, 20)) +>x : Symbol(x, Decl(negatedRepresentativeExamples.ts, 19, 13)) +>n : Symbol(n, Decl(negatedRepresentativeExamples.ts, 21, 10)) +>n : Symbol(n, Decl(negatedRepresentativeExamples.ts, 21, 10)) + +asValid(y, n => n >= 0); // Should error +>asValid : Symbol(asValid, Decl(negatedRepresentativeExamples.ts, 13, 20)) +>y : Symbol(y, Decl(negatedRepresentativeExamples.ts, 20, 13)) +>n : Symbol(n, Decl(negatedRepresentativeExamples.ts, 22, 10)) +>n : Symbol(n, Decl(negatedRepresentativeExamples.ts, 22, 10)) + +function tryAt(values: T[], index: number): T | undefined { +>tryAt : Symbol(tryAt, Decl(negatedRepresentativeExamples.ts, 22, 24)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 24, 15)) +>values : Symbol(values, Decl(negatedRepresentativeExamples.ts, 24, 40)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 24, 15)) +>index : Symbol(index, Decl(negatedRepresentativeExamples.ts, 24, 52)) +>T : Symbol(T, Decl(negatedRepresentativeExamples.ts, 24, 15)) + + return values[index]; +>values : Symbol(values, Decl(negatedRepresentativeExamples.ts, 24, 40)) +>index : Symbol(index, Decl(negatedRepresentativeExamples.ts, 24, 52)) +} + +declare const a: number[]; +>a : Symbol(a, Decl(negatedRepresentativeExamples.ts, 28, 13)) + +declare const b: (number | undefined)[]; +>b : Symbol(b, Decl(negatedRepresentativeExamples.ts, 29, 13)) + +tryAt(a, 0); // OK +>tryAt : Symbol(tryAt, Decl(negatedRepresentativeExamples.ts, 22, 24)) +>a : Symbol(a, Decl(negatedRepresentativeExamples.ts, 28, 13)) + +tryAt(b, 0); // Should error +>tryAt : Symbol(tryAt, Decl(negatedRepresentativeExamples.ts, 22, 24)) +>b : Symbol(b, Decl(negatedRepresentativeExamples.ts, 29, 13)) + diff --git a/tests/baselines/reference/negatedRepresentativeExamples.types b/tests/baselines/reference/negatedRepresentativeExamples.types new file mode 100644 index 0000000000000..69ba66305a1a6 --- /dev/null +++ b/tests/baselines/reference/negatedRepresentativeExamples.types @@ -0,0 +1,129 @@ +=== tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts === +// https://github.com/Microsoft/TypeScript/issues/7993 + +declare function ignore)>(value: T): void; +>ignore : >(value: T) => void +>value : T + +declare function readFileAsync(): Promise; +>readFileAsync : () => Promise + +declare function readFileSync(): string; +>readFileSync : () => string + +ignore(readFileSync()); // OK +>ignore(readFileSync()) : void +>ignore : >(value: T) => void +>readFileSync() : string +>readFileSync : () => string + +ignore(readFileAsync()); // Should error +>ignore(readFileAsync()) : any +>ignore : >(value: T) => void +>readFileAsync() : Promise +>readFileAsync : () => Promise + +declare function map(values: T[], map: (value: T) => U) : U[]; // validate map callback doesn't return void +>map : (values: T[], map: (value: T) => U) => U[] +>values : T[] +>map : (value: T) => U +>value : T + +function foo() {} +>foo : () => void + +map([1, 2, 3], n => n + 1); // OK +>map([1, 2, 3], n => n + 1) : number[] +>map : (values: T[], map: (value: T) => U) => U[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 +>n => n + 1 : (n: number) => number +>n : number +>n + 1 : number +>n : number +>1 : 1 + +map([1, 2, 3], foo); // Should error +>map([1, 2, 3], foo) : any +>map : (values: T[], map: (value: T) => U) => U[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 +>foo : () => void + +function asValid(value: T, isValid: (value: T) => boolean) : T | null { +>asValid : (value: T, isValid: (value: T) => boolean) => T | null +>null : null +>value : T +>isValid : (value: T) => boolean +>value : T +>null : null + + return isValid(value) ? value : null; +>isValid(value) ? value : null : T | null +>isValid(value) : boolean +>isValid : (value: T) => boolean +>value : T +>value : T +>null : null +} + +declare const x: number; +>x : number + +declare const y: number | null; +>y : number | null +>null : null + +asValid(x, n => n >= 0); // OK +>asValid(x, n => n >= 0) : number | null +>asValid : (value: T, isValid: (value: T) => boolean) => T | null +>x : number +>n => n >= 0 : (n: number) => boolean +>n : number +>n >= 0 : boolean +>n : number +>0 : 0 + +asValid(y, n => n >= 0); // Should error +>asValid(y, n => n >= 0) : any +>asValid : (value: T, isValid: (value: T) => boolean) => T | null +>y : number | null +>n => n >= 0 : (n: any) => boolean +>n : any +>n >= 0 : boolean +>n : any +>0 : 0 + +function tryAt(values: T[], index: number): T | undefined { +>tryAt : (values: T[], index: number) => T | undefined +>values : T[] +>index : number + + return values[index]; +>values[index] : T +>values : T[] +>index : number +} + +declare const a: number[]; +>a : number[] + +declare const b: (number | undefined)[]; +>b : (number | undefined)[] + +tryAt(a, 0); // OK +>tryAt(a, 0) : number | undefined +>tryAt : (values: T[], index: number) => T | undefined +>a : number[] +>0 : 0 + +tryAt(b, 0); // Should error +>tryAt(b, 0) : any +>tryAt : (values: T[], index: number) => T | undefined +>b : (number | undefined)[] +>0 : 0 + diff --git a/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.js b/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.js new file mode 100644 index 0000000000000..b7e87a8b1ecd0 --- /dev/null +++ b/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.js @@ -0,0 +1,10 @@ +//// [negatedTypeAppliesToFalseBranchOfConditional.ts] +// https://github.com/Microsoft/TypeScript/issues/26240 + +type OnlyNumber = T; +type ToNumber = + T extends string ? undefined : OnlyNumber; + + +//// [negatedTypeAppliesToFalseBranchOfConditional.js] +// https://github.com/Microsoft/TypeScript/issues/26240 diff --git a/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.symbols b/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.symbols new file mode 100644 index 0000000000000..011db07bc08eb --- /dev/null +++ b/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/types/negated/negatedTypeAppliesToFalseBranchOfConditional.ts === +// https://github.com/Microsoft/TypeScript/issues/26240 + +type OnlyNumber = T; +>OnlyNumber : Symbol(OnlyNumber, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 0, 0)) +>T : Symbol(T, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 2, 16)) +>T : Symbol(T, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 2, 16)) + +type ToNumber = +>ToNumber : Symbol(ToNumber, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 2, 38)) +>T : Symbol(T, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 3, 14)) + + T extends string ? undefined : OnlyNumber; +>T : Symbol(T, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 3, 14)) +>OnlyNumber : Symbol(OnlyNumber, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 0, 0)) +>T : Symbol(T, Decl(negatedTypeAppliesToFalseBranchOfConditional.ts, 3, 14)) + diff --git a/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.types b/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.types new file mode 100644 index 0000000000000..63482aca45a6c --- /dev/null +++ b/tests/baselines/reference/negatedTypeAppliesToFalseBranchOfConditional.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/types/negated/negatedTypeAppliesToFalseBranchOfConditional.ts === +// https://github.com/Microsoft/TypeScript/issues/26240 + +type OnlyNumber = T; +>OnlyNumber : T + +type ToNumber = +>ToNumber : ToNumber + + T extends string ? undefined : OnlyNumber; + diff --git a/tests/baselines/reference/negatedTypes.errors.txt b/tests/baselines/reference/negatedTypes.errors.txt new file mode 100644 index 0000000000000..d5013ed4e7b2c --- /dev/null +++ b/tests/baselines/reference/negatedTypes.errors.txt @@ -0,0 +1,309 @@ +tests/cases/conformance/types/negated/negatedTypes.ts(20,5): error TS2322: Type 'string' is not assignable to type 'not string'. +tests/cases/conformance/types/negated/negatedTypes.ts(21,5): error TS2322: Type '"ok"' is not assignable to type 'not string'. +tests/cases/conformance/types/negated/negatedTypes.ts(22,5): error TS2322: Type 'Literal' is not assignable to type 'not string'. +tests/cases/conformance/types/negated/negatedTypes.ts(26,5): error TS2322: Type 'unknown' is not assignable to type 'not string'. +tests/cases/conformance/types/negated/negatedTypes.ts(29,5): error TS2322: Type 'not string' is not assignable to type 'string'. +tests/cases/conformance/types/negated/negatedTypes.ts(30,5): error TS2322: Type 'not string' is not assignable to type '"ok"'. +tests/cases/conformance/types/negated/negatedTypes.ts(31,5): error TS2322: Type 'not string' is not assignable to type 'Literal'. +tests/cases/conformance/types/negated/negatedTypes.ts(32,5): error TS2322: Type 'not string' is not assignable to type 'number'. +tests/cases/conformance/types/negated/negatedTypes.ts(33,5): error TS2322: Type 'not string' is not assignable to type '0'. +tests/cases/conformance/types/negated/negatedTypes.ts(34,5): error TS2322: Type 'not string' is not assignable to type 'NumLiteral'. +tests/cases/conformance/types/negated/negatedTypes.ts(36,5): error TS2322: Type 'not string' is not assignable to type 'never'. +tests/cases/conformance/types/negated/negatedTypes.ts(49,5): error TS2741: Property 'x' is missing in type '{ y: any; }' but required in type '{ x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(51,5): error TS2322: Type 'not { x: any; }' is not assignable to type '{ x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(52,5): error TS2322: Type 'not { y: any; }' is not assignable to type '{ x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(53,5): error TS2322: Type 'not { x: any; y: any; }' is not assignable to type '{ x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(54,5): error TS2741: Property 'x' is missing in type 'not { x: any; } & not { y: any; }' but required in type '{ x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(55,5): error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type '{ x: any; }'. + Type 'not { x: any; }' is not assignable to type '{ x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(57,5): error TS2741: Property 'y' is missing in type '{ x: any; }' but required in type '{ y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(59,5): error TS2322: Type 'not { x: any; }' is not assignable to type '{ y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(60,5): error TS2322: Type 'not { y: any; }' is not assignable to type '{ y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(61,5): error TS2322: Type 'not { x: any; y: any; }' is not assignable to type '{ y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(62,5): error TS2741: Property 'y' is missing in type 'not { x: any; } & not { y: any; }' but required in type '{ y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(63,5): error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type '{ y: any; }'. + Type 'not { x: any; }' is not assignable to type '{ y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(65,5): error TS2741: Property 'y' is missing in type '{ x: any; }' but required in type '{ x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(66,5): error TS2741: Property 'x' is missing in type '{ y: any; }' but required in type '{ x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(67,5): error TS2322: Type 'not { x: any; }' is not assignable to type '{ x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(68,5): error TS2322: Type 'not { y: any; }' is not assignable to type '{ x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(69,5): error TS2322: Type 'not { x: any; y: any; }' is not assignable to type '{ x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(70,5): error TS2739: Type 'not { x: any; } & not { y: any; }' is missing the following properties from type '{ x: any; y: any; }': x, y +tests/cases/conformance/types/negated/negatedTypes.ts(71,5): error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type '{ x: any; y: any; }'. + Type 'not { x: any; }' is not assignable to type '{ x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(73,5): error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(74,5): error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(75,5): error TS2322: Type 'not { y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(76,5): error TS2322: Type 'not { x: any; y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(78,5): error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type 'not { x: any; }'. + Type 'not { y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(80,5): error TS2322: Type '{ x: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(81,5): error TS2322: Type '{ y: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(82,5): error TS2322: Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(83,5): error TS2322: Type 'not { x: any; y: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(85,5): error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type 'not { y: any; }'. + Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(87,5): error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(88,5): error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(89,5): error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(95,5): error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type '{ x: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(96,5): error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type '{ y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(97,5): error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(98,5): error TS2322: Type 'not { x: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(99,5): error TS2322: Type 'not { y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type 'not { y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(100,5): error TS2322: Type 'not { x: any; y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type 'not { x: any; y: any; }' is not assignable to type 'not { x: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(101,5): error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type 'not { x: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. + Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(103,5): error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; } | not { y: any; }'. + Type '{ x: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(104,5): error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; } | not { y: any; }'. + Type '{ y: any; }' is not assignable to type 'not { y: any; }'. +tests/cases/conformance/types/negated/negatedTypes.ts(105,5): error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; } | not { y: any; }'. + Type '{ x: any; y: any; }' is not assignable to type 'not { y: any; }'. + + +==== tests/cases/conformance/types/negated/negatedTypes.ts (53 errors) ==== + enum Literal { + ok = "ok" + } + + enum NumLiteral { + Val + } + + function f1( + notString: not string, + str: string, + strlit: "ok", + strenum: Literal, + num: number, + numlit: 0, + numenum: NumLiteral, + unknownVal: unknown, + neverVal: never + ) { + notString = str; // not ok + ~~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'not string'. + notString = strlit; // not ok + ~~~~~~~~~ +!!! error TS2322: Type '"ok"' is not assignable to type 'not string'. + notString = strenum; // not ok + ~~~~~~~~~ +!!! error TS2322: Type 'Literal' is not assignable to type 'not string'. + notString = num; // ok + notString = numlit; // ok + notString = numenum; // ok + notString = unknownVal; // not ok (unknown is all values, includes string) + ~~~~~~~~~ +!!! error TS2322: Type 'unknown' is not assignable to type 'not string'. + notString = neverVal; // ok (never is empty set of types, doesn't include string) + + str = notString; // not ok + ~~~ +!!! error TS2322: Type 'not string' is not assignable to type 'string'. + strlit = notString; // not ok + ~~~~~~ +!!! error TS2322: Type 'not string' is not assignable to type '"ok"'. + strenum = notString; // not ok + ~~~~~~~ +!!! error TS2322: Type 'not string' is not assignable to type 'Literal'. + num = notString; // not ok + ~~~ +!!! error TS2322: Type 'not string' is not assignable to type 'number'. + numlit = notString; // not ok + ~~~~~~ +!!! error TS2322: Type 'not string' is not assignable to type '0'. + numenum = notString; // not ok + ~~~~~~~ +!!! error TS2322: Type 'not string' is not assignable to type 'NumLiteral'. + unknownVal = notString; // ok + neverVal = notString; // not ok + ~~~~~~~~ +!!! error TS2322: Type 'not string' is not assignable to type 'never'. + } + + function f2( + x: { x }, + y: { y }, + xy: {x, y}, + nx: not typeof x, + ny: not typeof y, + nxy: not typeof xy, + neither: not (typeof x | typeof y), + notBoth: not (typeof x & typeof y) + ) { + x = y; // not ok + ~ +!!! error TS2741: Property 'x' is missing in type '{ y: any; }' but required in type '{ x: any; }'. +!!! related TS2728 tests/cases/conformance/types/negated/negatedTypes.ts:40:10: 'x' is declared here. + x = xy; // ok + x = nx; // not ok + ~ +!!! error TS2322: Type 'not { x: any; }' is not assignable to type '{ x: any; }'. + x = ny; // not ok + ~ +!!! error TS2322: Type 'not { y: any; }' is not assignable to type '{ x: any; }'. + x = nxy; // not ok + ~ +!!! error TS2322: Type 'not { x: any; y: any; }' is not assignable to type '{ x: any; }'. + x = neither; // not ok + ~ +!!! error TS2741: Property 'x' is missing in type 'not { x: any; } & not { y: any; }' but required in type '{ x: any; }'. +!!! related TS2728 tests/cases/conformance/types/negated/negatedTypes.ts:40:10: 'x' is declared here. + x = notBoth; // not ok + ~ +!!! error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type '{ x: any; }'. +!!! error TS2322: Type 'not { x: any; }' is not assignable to type '{ x: any; }'. + + y = x; // not ok + ~ +!!! error TS2741: Property 'y' is missing in type '{ x: any; }' but required in type '{ y: any; }'. +!!! related TS2728 tests/cases/conformance/types/negated/negatedTypes.ts:41:10: 'y' is declared here. + y = xy; // ok + y = nx; // not ok + ~ +!!! error TS2322: Type 'not { x: any; }' is not assignable to type '{ y: any; }'. + y = ny; // not ok + ~ +!!! error TS2322: Type 'not { y: any; }' is not assignable to type '{ y: any; }'. + y = nxy; // not ok + ~ +!!! error TS2322: Type 'not { x: any; y: any; }' is not assignable to type '{ y: any; }'. + y = neither; // not ok + ~ +!!! error TS2741: Property 'y' is missing in type 'not { x: any; } & not { y: any; }' but required in type '{ y: any; }'. +!!! related TS2728 tests/cases/conformance/types/negated/negatedTypes.ts:41:10: 'y' is declared here. + y = notBoth; // not ok + ~ +!!! error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type '{ y: any; }'. +!!! error TS2322: Type 'not { x: any; }' is not assignable to type '{ y: any; }'. + + xy = x; // not ok + ~~ +!!! error TS2741: Property 'y' is missing in type '{ x: any; }' but required in type '{ x: any; y: any; }'. +!!! related TS2728 tests/cases/conformance/types/negated/negatedTypes.ts:42:13: 'y' is declared here. + xy = y; // not ok + ~~ +!!! error TS2741: Property 'x' is missing in type '{ y: any; }' but required in type '{ x: any; y: any; }'. +!!! related TS2728 tests/cases/conformance/types/negated/negatedTypes.ts:42:10: 'x' is declared here. + xy = nx; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; }' is not assignable to type '{ x: any; y: any; }'. + xy = ny; // not ok + ~~ +!!! error TS2322: Type 'not { y: any; }' is not assignable to type '{ x: any; y: any; }'. + xy = nxy; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; y: any; }' is not assignable to type '{ x: any; y: any; }'. + xy = neither; // not ok + ~~ +!!! error TS2739: Type 'not { x: any; } & not { y: any; }' is missing the following properties from type '{ x: any; y: any; }': x, y + xy = notBoth; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type '{ x: any; y: any; }'. +!!! error TS2322: Type 'not { x: any; }' is not assignable to type '{ x: any; y: any; }'. + + nx = x; // not ok + ~~ +!!! error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; }'. + nx = y; // not ok + ~~ +!!! error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; }'. + nx = ny; // not ok + ~~ +!!! error TS2322: Type 'not { y: any; }' is not assignable to type 'not { x: any; }'. + nx = nxy; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; y: any; }' is not assignable to type 'not { x: any; }'. + nx = neither; // ok + nx = notBoth; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type 'not { x: any; }'. +!!! error TS2322: Type 'not { y: any; }' is not assignable to type 'not { x: any; }'. + + ny = x; // not ok + ~~ +!!! error TS2322: Type '{ x: any; }' is not assignable to type 'not { y: any; }'. + ny = y; // not ok + ~~ +!!! error TS2322: Type '{ y: any; }' is not assignable to type 'not { y: any; }'. + ny = nx; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. + ny = nxy; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; y: any; }' is not assignable to type 'not { y: any; }'. + ny = neither; // ok + ny = notBoth; // not ok + ~~ +!!! error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type 'not { y: any; }'. +!!! error TS2322: Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. + + nxy = x; // not ok + ~~~ +!!! error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; y: any; }'. + nxy = y; // not ok + ~~~ +!!! error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; y: any; }'. + nxy = xy; // not ok + ~~~ +!!! error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; y: any; }'. + nxy = nx; // ok + nxy = ny; // ok + nxy = neither; // ok + nxy = notBoth; // ok + + neither = x; // not ok + ~~~~~~~ +!!! error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; }'. + neither = y; // not ok + ~~~~~~~ +!!! error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; }'. + neither = xy; // not ok + ~~~~~~~ +!!! error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; }'. + neither = nx; // not ok + ~~~~~~~ +!!! error TS2322: Type 'not { x: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. + neither = ny; // not ok + ~~~~~~~ +!!! error TS2322: Type 'not { y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type 'not { y: any; }' is not assignable to type 'not { x: any; }'. + neither = nxy; // not ok + ~~~~~~~ +!!! error TS2322: Type 'not { x: any; y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type 'not { x: any; y: any; }' is not assignable to type 'not { x: any; }'. + neither = notBoth; // not ok + ~~~~~~~ +!!! error TS2322: Type 'not { x: any; } | not { y: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type 'not { x: any; }' is not assignable to type 'not { x: any; } & not { y: any; }'. +!!! error TS2322: Type 'not { x: any; }' is not assignable to type 'not { y: any; }'. + + notBoth = x; // not ok + ~~~~~~~ +!!! error TS2322: Type '{ x: any; }' is not assignable to type 'not { x: any; } | not { y: any; }'. +!!! error TS2322: Type '{ x: any; }' is not assignable to type 'not { y: any; }'. + notBoth = y; // not ok + ~~~~~~~ +!!! error TS2322: Type '{ y: any; }' is not assignable to type 'not { x: any; } | not { y: any; }'. +!!! error TS2322: Type '{ y: any; }' is not assignable to type 'not { y: any; }'. + notBoth = xy; // not ok + ~~~~~~~ +!!! error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { x: any; } | not { y: any; }'. +!!! error TS2322: Type '{ x: any; y: any; }' is not assignable to type 'not { y: any; }'. + notBoth = nx; // ok + notBoth = ny; // ok + notBoth = neither; // ok + } \ No newline at end of file diff --git a/tests/baselines/reference/negatedTypes.js b/tests/baselines/reference/negatedTypes.js new file mode 100644 index 0000000000000..0e77e1376b37f --- /dev/null +++ b/tests/baselines/reference/negatedTypes.js @@ -0,0 +1,193 @@ +//// [negatedTypes.ts] +enum Literal { + ok = "ok" +} + +enum NumLiteral { + Val +} + +function f1( + notString: not string, + str: string, + strlit: "ok", + strenum: Literal, + num: number, + numlit: 0, + numenum: NumLiteral, + unknownVal: unknown, + neverVal: never +) { + notString = str; // not ok + notString = strlit; // not ok + notString = strenum; // not ok + notString = num; // ok + notString = numlit; // ok + notString = numenum; // ok + notString = unknownVal; // not ok (unknown is all values, includes string) + notString = neverVal; // ok (never is empty set of types, doesn't include string) + + str = notString; // not ok + strlit = notString; // not ok + strenum = notString; // not ok + num = notString; // not ok + numlit = notString; // not ok + numenum = notString; // not ok + unknownVal = notString; // ok + neverVal = notString; // not ok +} + +function f2( + x: { x }, + y: { y }, + xy: {x, y}, + nx: not typeof x, + ny: not typeof y, + nxy: not typeof xy, + neither: not (typeof x | typeof y), + notBoth: not (typeof x & typeof y) +) { + x = y; // not ok + x = xy; // ok + x = nx; // not ok + x = ny; // not ok + x = nxy; // not ok + x = neither; // not ok + x = notBoth; // not ok + + y = x; // not ok + y = xy; // ok + y = nx; // not ok + y = ny; // not ok + y = nxy; // not ok + y = neither; // not ok + y = notBoth; // not ok + + xy = x; // not ok + xy = y; // not ok + xy = nx; // not ok + xy = ny; // not ok + xy = nxy; // not ok + xy = neither; // not ok + xy = notBoth; // not ok + + nx = x; // not ok + nx = y; // not ok + nx = ny; // not ok + nx = nxy; // not ok + nx = neither; // ok + nx = notBoth; // not ok + + ny = x; // not ok + ny = y; // not ok + ny = nx; // not ok + ny = nxy; // not ok + ny = neither; // ok + ny = notBoth; // not ok + + nxy = x; // not ok + nxy = y; // not ok + nxy = xy; // not ok + nxy = nx; // ok + nxy = ny; // ok + nxy = neither; // ok + nxy = notBoth; // ok + + neither = x; // not ok + neither = y; // not ok + neither = xy; // not ok + neither = nx; // not ok + neither = ny; // not ok + neither = nxy; // not ok + neither = notBoth; // not ok + + notBoth = x; // not ok + notBoth = y; // not ok + notBoth = xy; // not ok + notBoth = nx; // ok + notBoth = ny; // ok + notBoth = neither; // ok +} + +//// [negatedTypes.js] +var Literal; +(function (Literal) { + Literal["ok"] = "ok"; +})(Literal || (Literal = {})); +var NumLiteral; +(function (NumLiteral) { + NumLiteral[NumLiteral["Val"] = 0] = "Val"; +})(NumLiteral || (NumLiteral = {})); +function f1(notString, str, strlit, strenum, num, numlit, numenum, unknownVal, neverVal) { + notString = str; // not ok + notString = strlit; // not ok + notString = strenum; // not ok + notString = num; // ok + notString = numlit; // ok + notString = numenum; // ok + notString = unknownVal; // not ok (unknown is all values, includes string) + notString = neverVal; // ok (never is empty set of types, doesn't include string) + str = notString; // not ok + strlit = notString; // not ok + strenum = notString; // not ok + num = notString; // not ok + numlit = notString; // not ok + numenum = notString; // not ok + unknownVal = notString; // ok + neverVal = notString; // not ok +} +function f2(x, y, xy, nx, ny, nxy, neither, notBoth) { + x = y; // not ok + x = xy; // ok + x = nx; // not ok + x = ny; // not ok + x = nxy; // not ok + x = neither; // not ok + x = notBoth; // not ok + y = x; // not ok + y = xy; // ok + y = nx; // not ok + y = ny; // not ok + y = nxy; // not ok + y = neither; // not ok + y = notBoth; // not ok + xy = x; // not ok + xy = y; // not ok + xy = nx; // not ok + xy = ny; // not ok + xy = nxy; // not ok + xy = neither; // not ok + xy = notBoth; // not ok + nx = x; // not ok + nx = y; // not ok + nx = ny; // not ok + nx = nxy; // not ok + nx = neither; // ok + nx = notBoth; // not ok + ny = x; // not ok + ny = y; // not ok + ny = nx; // not ok + ny = nxy; // not ok + ny = neither; // ok + ny = notBoth; // not ok + nxy = x; // not ok + nxy = y; // not ok + nxy = xy; // not ok + nxy = nx; // ok + nxy = ny; // ok + nxy = neither; // ok + nxy = notBoth; // ok + neither = x; // not ok + neither = y; // not ok + neither = xy; // not ok + neither = nx; // not ok + neither = ny; // not ok + neither = nxy; // not ok + neither = notBoth; // not ok + notBoth = x; // not ok + notBoth = y; // not ok + notBoth = xy; // not ok + notBoth = nx; // ok + notBoth = ny; // ok + notBoth = neither; // ok +} diff --git a/tests/baselines/reference/negatedTypes.symbols b/tests/baselines/reference/negatedTypes.symbols new file mode 100644 index 0000000000000..de047605152de --- /dev/null +++ b/tests/baselines/reference/negatedTypes.symbols @@ -0,0 +1,364 @@ +=== tests/cases/conformance/types/negated/negatedTypes.ts === +enum Literal { +>Literal : Symbol(Literal, Decl(negatedTypes.ts, 0, 0)) + + ok = "ok" +>ok : Symbol(Literal.ok, Decl(negatedTypes.ts, 0, 14)) +} + +enum NumLiteral { +>NumLiteral : Symbol(NumLiteral, Decl(negatedTypes.ts, 2, 1)) + + Val +>Val : Symbol(NumLiteral.Val, Decl(negatedTypes.ts, 4, 17)) +} + +function f1( +>f1 : Symbol(f1, Decl(negatedTypes.ts, 6, 1)) + + notString: not string, +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + str: string, +>str : Symbol(str, Decl(negatedTypes.ts, 9, 26)) + + strlit: "ok", +>strlit : Symbol(strlit, Decl(negatedTypes.ts, 10, 16)) + + strenum: Literal, +>strenum : Symbol(strenum, Decl(negatedTypes.ts, 11, 17)) +>Literal : Symbol(Literal, Decl(negatedTypes.ts, 0, 0)) + + num: number, +>num : Symbol(num, Decl(negatedTypes.ts, 12, 21)) + + numlit: 0, +>numlit : Symbol(numlit, Decl(negatedTypes.ts, 13, 16)) + + numenum: NumLiteral, +>numenum : Symbol(numenum, Decl(negatedTypes.ts, 14, 14)) +>NumLiteral : Symbol(NumLiteral, Decl(negatedTypes.ts, 2, 1)) + + unknownVal: unknown, +>unknownVal : Symbol(unknownVal, Decl(negatedTypes.ts, 15, 24)) + + neverVal: never +>neverVal : Symbol(neverVal, Decl(negatedTypes.ts, 16, 24)) + +) { + notString = str; // not ok +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>str : Symbol(str, Decl(negatedTypes.ts, 9, 26)) + + notString = strlit; // not ok +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>strlit : Symbol(strlit, Decl(negatedTypes.ts, 10, 16)) + + notString = strenum; // not ok +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>strenum : Symbol(strenum, Decl(negatedTypes.ts, 11, 17)) + + notString = num; // ok +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>num : Symbol(num, Decl(negatedTypes.ts, 12, 21)) + + notString = numlit; // ok +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>numlit : Symbol(numlit, Decl(negatedTypes.ts, 13, 16)) + + notString = numenum; // ok +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>numenum : Symbol(numenum, Decl(negatedTypes.ts, 14, 14)) + + notString = unknownVal; // not ok (unknown is all values, includes string) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>unknownVal : Symbol(unknownVal, Decl(negatedTypes.ts, 15, 24)) + + notString = neverVal; // ok (never is empty set of types, doesn't include string) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +>neverVal : Symbol(neverVal, Decl(negatedTypes.ts, 16, 24)) + + str = notString; // not ok +>str : Symbol(str, Decl(negatedTypes.ts, 9, 26)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + strlit = notString; // not ok +>strlit : Symbol(strlit, Decl(negatedTypes.ts, 10, 16)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + strenum = notString; // not ok +>strenum : Symbol(strenum, Decl(negatedTypes.ts, 11, 17)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + num = notString; // not ok +>num : Symbol(num, Decl(negatedTypes.ts, 12, 21)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + numlit = notString; // not ok +>numlit : Symbol(numlit, Decl(negatedTypes.ts, 13, 16)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + numenum = notString; // not ok +>numenum : Symbol(numenum, Decl(negatedTypes.ts, 14, 14)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + unknownVal = notString; // ok +>unknownVal : Symbol(unknownVal, Decl(negatedTypes.ts, 15, 24)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) + + neverVal = notString; // not ok +>neverVal : Symbol(neverVal, Decl(negatedTypes.ts, 16, 24)) +>notString : Symbol(notString, Decl(negatedTypes.ts, 8, 12)) +} + +function f2( +>f2 : Symbol(f2, Decl(negatedTypes.ts, 36, 1)) + + x: { x }, +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>x : Symbol(x, Decl(negatedTypes.ts, 39, 8)) + + y: { y }, +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>y : Symbol(y, Decl(negatedTypes.ts, 40, 8)) + + xy: {x, y}, +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>x : Symbol(x, Decl(negatedTypes.ts, 41, 9)) +>y : Symbol(y, Decl(negatedTypes.ts, 41, 11)) + + nx: not typeof x, +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + ny: not typeof y, +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + nxy: not typeof xy, +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) + + neither: not (typeof x | typeof y), +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + notBoth: not (typeof x & typeof y) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + +) { + x = y; // not ok +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + x = xy; // ok +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) + + x = nx; // not ok +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) + + x = ny; // not ok +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) + + x = nxy; // not ok +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) + + x = neither; // not ok +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) + + x = notBoth; // not ok +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) + + y = x; // not ok +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + y = xy; // ok +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) + + y = nx; // not ok +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) + + y = ny; // not ok +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) + + y = nxy; // not ok +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) + + y = neither; // not ok +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) + + y = notBoth; // not ok +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) + + xy = x; // not ok +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + xy = y; // not ok +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + xy = nx; // not ok +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) + + xy = ny; // not ok +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) + + xy = nxy; // not ok +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) + + xy = neither; // not ok +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) + + xy = notBoth; // not ok +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) + + nx = x; // not ok +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + nx = y; // not ok +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + nx = ny; // not ok +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) + + nx = nxy; // not ok +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) + + nx = neither; // ok +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) + + nx = notBoth; // not ok +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) + + ny = x; // not ok +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + ny = y; // not ok +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + ny = nx; // not ok +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) + + ny = nxy; // not ok +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) + + ny = neither; // ok +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) + + ny = notBoth; // not ok +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) + + nxy = x; // not ok +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + nxy = y; // not ok +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + nxy = xy; // not ok +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) + + nxy = nx; // ok +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) + + nxy = ny; // ok +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) + + nxy = neither; // ok +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) + + nxy = notBoth; // ok +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) + + neither = x; // not ok +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + neither = y; // not ok +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + neither = xy; // not ok +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) + + neither = nx; // not ok +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) + + neither = ny; // not ok +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) + + neither = nxy; // not ok +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>nxy : Symbol(nxy, Decl(negatedTypes.ts, 43, 21)) + + neither = notBoth; // not ok +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) + + notBoth = x; // not ok +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) +>x : Symbol(x, Decl(negatedTypes.ts, 38, 12)) + + notBoth = y; // not ok +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) +>y : Symbol(y, Decl(negatedTypes.ts, 39, 13)) + + notBoth = xy; // not ok +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) +>xy : Symbol(xy, Decl(negatedTypes.ts, 40, 13)) + + notBoth = nx; // ok +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) +>nx : Symbol(nx, Decl(negatedTypes.ts, 41, 15)) + + notBoth = ny; // ok +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) +>ny : Symbol(ny, Decl(negatedTypes.ts, 42, 21)) + + notBoth = neither; // ok +>notBoth : Symbol(notBoth, Decl(negatedTypes.ts, 45, 39)) +>neither : Symbol(neither, Decl(negatedTypes.ts, 44, 23)) +} diff --git a/tests/baselines/reference/negatedTypes.types b/tests/baselines/reference/negatedTypes.types new file mode 100644 index 0000000000000..80748bc60c6df --- /dev/null +++ b/tests/baselines/reference/negatedTypes.types @@ -0,0 +1,432 @@ +=== tests/cases/conformance/types/negated/negatedTypes.ts === +enum Literal { +>Literal : Literal + + ok = "ok" +>ok : Literal.ok +>"ok" : "ok" +} + +enum NumLiteral { +>NumLiteral : NumLiteral + + Val +>Val : NumLiteral.Val +} + +function f1( +>f1 : (notString: not string, str: string, strlit: "ok", strenum: Literal, num: number, numlit: 0, numenum: NumLiteral, unknownVal: unknown, neverVal: never) => void + + notString: not string, +>notString : not string + + str: string, +>str : string + + strlit: "ok", +>strlit : "ok" + + strenum: Literal, +>strenum : Literal + + num: number, +>num : number + + numlit: 0, +>numlit : 0 + + numenum: NumLiteral, +>numenum : NumLiteral + + unknownVal: unknown, +>unknownVal : unknown + + neverVal: never +>neverVal : never + +) { + notString = str; // not ok +>notString = str : string +>notString : not string +>str : string + + notString = strlit; // not ok +>notString = strlit : "ok" +>notString : not string +>strlit : "ok" + + notString = strenum; // not ok +>notString = strenum : Literal +>notString : not string +>strenum : Literal + + notString = num; // ok +>notString = num : number +>notString : not string +>num : number + + notString = numlit; // ok +>notString = numlit : 0 +>notString : not string +>numlit : 0 + + notString = numenum; // ok +>notString = numenum : NumLiteral +>notString : not string +>numenum : NumLiteral + + notString = unknownVal; // not ok (unknown is all values, includes string) +>notString = unknownVal : unknown +>notString : not string +>unknownVal : unknown + + notString = neverVal; // ok (never is empty set of types, doesn't include string) +>notString = neverVal : never +>notString : not string +>neverVal : never + + str = notString; // not ok +>str = notString : not string +>str : string +>notString : not string + + strlit = notString; // not ok +>strlit = notString : not string +>strlit : "ok" +>notString : not string + + strenum = notString; // not ok +>strenum = notString : not string +>strenum : Literal +>notString : not string + + num = notString; // not ok +>num = notString : not string +>num : number +>notString : not string + + numlit = notString; // not ok +>numlit = notString : not string +>numlit : 0 +>notString : not string + + numenum = notString; // not ok +>numenum = notString : not string +>numenum : NumLiteral +>notString : not string + + unknownVal = notString; // ok +>unknownVal = notString : not string +>unknownVal : unknown +>notString : not string + + neverVal = notString; // not ok +>neverVal = notString : not string +>neverVal : never +>notString : not string +} + +function f2( +>f2 : (x: { x: any; }, y: { y: any; }, xy: { x: any; y: any; }, nx: not { x: any; }, ny: not { y: any; }, nxy: not { x: any; y: any; }, neither: not { x: any; } & not { y: any; }, notBoth: not { x: any; } | not { y: any; }) => void + + x: { x }, +>x : { x: any; } +>x : any + + y: { y }, +>y : { y: any; } +>y : any + + xy: {x, y}, +>xy : { x: any; y: any; } +>x : any +>y : any + + nx: not typeof x, +>nx : not { x: any; } +>x : { x: any; } + + ny: not typeof y, +>ny : not { y: any; } +>y : { y: any; } + + nxy: not typeof xy, +>nxy : not { x: any; y: any; } +>xy : { x: any; y: any; } + + neither: not (typeof x | typeof y), +>neither : not { x: any; } & not { y: any; } +>x : { x: any; } +>y : { y: any; } + + notBoth: not (typeof x & typeof y) +>notBoth : not { x: any; } | not { y: any; } +>x : { x: any; } +>y : { y: any; } + +) { + x = y; // not ok +>x = y : { y: any; } +>x : { x: any; } +>y : { y: any; } + + x = xy; // ok +>x = xy : { x: any; y: any; } +>x : { x: any; } +>xy : { x: any; y: any; } + + x = nx; // not ok +>x = nx : not { x: any; } +>x : { x: any; } +>nx : not { x: any; } + + x = ny; // not ok +>x = ny : not { y: any; } +>x : { x: any; } +>ny : not { y: any; } + + x = nxy; // not ok +>x = nxy : not { x: any; y: any; } +>x : { x: any; } +>nxy : not { x: any; y: any; } + + x = neither; // not ok +>x = neither : not { x: any; } & not { y: any; } +>x : { x: any; } +>neither : not { x: any; } & not { y: any; } + + x = notBoth; // not ok +>x = notBoth : not { x: any; } | not { y: any; } +>x : { x: any; } +>notBoth : not { x: any; } | not { y: any; } + + y = x; // not ok +>y = x : { x: any; } +>y : { y: any; } +>x : { x: any; } + + y = xy; // ok +>y = xy : { x: any; y: any; } +>y : { y: any; } +>xy : { x: any; y: any; } + + y = nx; // not ok +>y = nx : not { x: any; } +>y : { y: any; } +>nx : not { x: any; } + + y = ny; // not ok +>y = ny : not { y: any; } +>y : { y: any; } +>ny : not { y: any; } + + y = nxy; // not ok +>y = nxy : not { x: any; y: any; } +>y : { y: any; } +>nxy : not { x: any; y: any; } + + y = neither; // not ok +>y = neither : not { x: any; } & not { y: any; } +>y : { y: any; } +>neither : not { x: any; } & not { y: any; } + + y = notBoth; // not ok +>y = notBoth : not { x: any; } | not { y: any; } +>y : { y: any; } +>notBoth : not { x: any; } | not { y: any; } + + xy = x; // not ok +>xy = x : { x: any; } +>xy : { x: any; y: any; } +>x : { x: any; } + + xy = y; // not ok +>xy = y : { y: any; } +>xy : { x: any; y: any; } +>y : { y: any; } + + xy = nx; // not ok +>xy = nx : not { x: any; } +>xy : { x: any; y: any; } +>nx : not { x: any; } + + xy = ny; // not ok +>xy = ny : not { y: any; } +>xy : { x: any; y: any; } +>ny : not { y: any; } + + xy = nxy; // not ok +>xy = nxy : not { x: any; y: any; } +>xy : { x: any; y: any; } +>nxy : not { x: any; y: any; } + + xy = neither; // not ok +>xy = neither : not { x: any; } & not { y: any; } +>xy : { x: any; y: any; } +>neither : not { x: any; } & not { y: any; } + + xy = notBoth; // not ok +>xy = notBoth : not { x: any; } | not { y: any; } +>xy : { x: any; y: any; } +>notBoth : not { x: any; } | not { y: any; } + + nx = x; // not ok +>nx = x : { x: any; } +>nx : not { x: any; } +>x : { x: any; } + + nx = y; // not ok +>nx = y : { y: any; } +>nx : not { x: any; } +>y : { y: any; } + + nx = ny; // not ok +>nx = ny : not { y: any; } +>nx : not { x: any; } +>ny : not { y: any; } + + nx = nxy; // not ok +>nx = nxy : not { x: any; y: any; } +>nx : not { x: any; } +>nxy : not { x: any; y: any; } + + nx = neither; // ok +>nx = neither : not { x: any; } & not { y: any; } +>nx : not { x: any; } +>neither : not { x: any; } & not { y: any; } + + nx = notBoth; // not ok +>nx = notBoth : not { x: any; } | not { y: any; } +>nx : not { x: any; } +>notBoth : not { x: any; } | not { y: any; } + + ny = x; // not ok +>ny = x : { x: any; } +>ny : not { y: any; } +>x : { x: any; } + + ny = y; // not ok +>ny = y : { y: any; } +>ny : not { y: any; } +>y : { y: any; } + + ny = nx; // not ok +>ny = nx : not { x: any; } +>ny : not { y: any; } +>nx : not { x: any; } + + ny = nxy; // not ok +>ny = nxy : not { x: any; y: any; } +>ny : not { y: any; } +>nxy : not { x: any; y: any; } + + ny = neither; // ok +>ny = neither : not { x: any; } & not { y: any; } +>ny : not { y: any; } +>neither : not { x: any; } & not { y: any; } + + ny = notBoth; // not ok +>ny = notBoth : not { x: any; } | not { y: any; } +>ny : not { y: any; } +>notBoth : not { x: any; } | not { y: any; } + + nxy = x; // not ok +>nxy = x : { x: any; } +>nxy : not { x: any; y: any; } +>x : { x: any; } + + nxy = y; // not ok +>nxy = y : { y: any; } +>nxy : not { x: any; y: any; } +>y : { y: any; } + + nxy = xy; // not ok +>nxy = xy : { x: any; y: any; } +>nxy : not { x: any; y: any; } +>xy : { x: any; y: any; } + + nxy = nx; // ok +>nxy = nx : not { x: any; } +>nxy : not { x: any; y: any; } +>nx : not { x: any; } + + nxy = ny; // ok +>nxy = ny : not { y: any; } +>nxy : not { x: any; y: any; } +>ny : not { y: any; } + + nxy = neither; // ok +>nxy = neither : not { x: any; } & not { y: any; } +>nxy : not { x: any; y: any; } +>neither : not { x: any; } & not { y: any; } + + nxy = notBoth; // ok +>nxy = notBoth : not { x: any; } | not { y: any; } +>nxy : not { x: any; y: any; } +>notBoth : not { x: any; } | not { y: any; } + + neither = x; // not ok +>neither = x : { x: any; } +>neither : not { x: any; } & not { y: any; } +>x : { x: any; } + + neither = y; // not ok +>neither = y : { y: any; } +>neither : not { x: any; } & not { y: any; } +>y : { y: any; } + + neither = xy; // not ok +>neither = xy : { x: any; y: any; } +>neither : not { x: any; } & not { y: any; } +>xy : { x: any; y: any; } + + neither = nx; // not ok +>neither = nx : not { x: any; } +>neither : not { x: any; } & not { y: any; } +>nx : not { x: any; } + + neither = ny; // not ok +>neither = ny : not { y: any; } +>neither : not { x: any; } & not { y: any; } +>ny : not { y: any; } + + neither = nxy; // not ok +>neither = nxy : not { x: any; y: any; } +>neither : not { x: any; } & not { y: any; } +>nxy : not { x: any; y: any; } + + neither = notBoth; // not ok +>neither = notBoth : not { x: any; } | not { y: any; } +>neither : not { x: any; } & not { y: any; } +>notBoth : not { x: any; } | not { y: any; } + + notBoth = x; // not ok +>notBoth = x : { x: any; } +>notBoth : not { x: any; } | not { y: any; } +>x : { x: any; } + + notBoth = y; // not ok +>notBoth = y : { y: any; } +>notBoth : not { x: any; } | not { y: any; } +>y : { y: any; } + + notBoth = xy; // not ok +>notBoth = xy : { x: any; y: any; } +>notBoth : not { x: any; } | not { y: any; } +>xy : { x: any; y: any; } + + notBoth = nx; // ok +>notBoth = nx : not { x: any; } +>notBoth : not { x: any; } | not { y: any; } +>nx : not { x: any; } + + notBoth = ny; // ok +>notBoth = ny : not { y: any; } +>notBoth : not { x: any; } | not { y: any; } +>ny : not { y: any; } + + notBoth = neither; // ok +>notBoth = neither : not { x: any; } & not { y: any; } +>notBoth : not { x: any; } | not { y: any; } +>neither : not { x: any; } & not { y: any; } +} diff --git a/tests/baselines/reference/negatedTypesControlFlow.js b/tests/baselines/reference/negatedTypesControlFlow.js new file mode 100644 index 0000000000000..d859a087aabca --- /dev/null +++ b/tests/baselines/reference/negatedTypesControlFlow.js @@ -0,0 +1,33 @@ +//// [negatedTypesControlFlow.ts] +interface A { type: "a", data: number } +interface B { type: "b", data: string } +interface Unknown { type: string & not ("a"|"b"), data: object } +type ABU = A | B | Unknown; +declare function needsNumber(x: number): void; +declare function needsString(x: string): void; +declare function needsObject(x: object): void; +declare var x: ABU; + +if (x.type === "a") { + let y = x.data; + needsNumber(y); +} +else if (x.type === "b") { + needsString(x.data); +} +else { + needsObject(x.data); +} + + +//// [negatedTypesControlFlow.js] +if (x.type === "a") { + var y = x.data; + needsNumber(y); +} +else if (x.type === "b") { + needsString(x.data); +} +else { + needsObject(x.data); +} diff --git a/tests/baselines/reference/negatedTypesControlFlow.symbols b/tests/baselines/reference/negatedTypesControlFlow.symbols new file mode 100644 index 0000000000000..e1ed2ef8958a5 --- /dev/null +++ b/tests/baselines/reference/negatedTypesControlFlow.symbols @@ -0,0 +1,72 @@ +=== tests/cases/conformance/types/negated/negatedTypesControlFlow.ts === +interface A { type: "a", data: number } +>A : Symbol(A, Decl(negatedTypesControlFlow.ts, 0, 0)) +>type : Symbol(A.type, Decl(negatedTypesControlFlow.ts, 0, 13)) +>data : Symbol(A.data, Decl(negatedTypesControlFlow.ts, 0, 24)) + +interface B { type: "b", data: string } +>B : Symbol(B, Decl(negatedTypesControlFlow.ts, 0, 39)) +>type : Symbol(B.type, Decl(negatedTypesControlFlow.ts, 1, 13)) +>data : Symbol(B.data, Decl(negatedTypesControlFlow.ts, 1, 24)) + +interface Unknown { type: string & not ("a"|"b"), data: object } +>Unknown : Symbol(Unknown, Decl(negatedTypesControlFlow.ts, 1, 39)) +>type : Symbol(Unknown.type, Decl(negatedTypesControlFlow.ts, 2, 19)) +>data : Symbol(Unknown.data, Decl(negatedTypesControlFlow.ts, 2, 49)) + +type ABU = A | B | Unknown; +>ABU : Symbol(ABU, Decl(negatedTypesControlFlow.ts, 2, 64)) +>A : Symbol(A, Decl(negatedTypesControlFlow.ts, 0, 0)) +>B : Symbol(B, Decl(negatedTypesControlFlow.ts, 0, 39)) +>Unknown : Symbol(Unknown, Decl(negatedTypesControlFlow.ts, 1, 39)) + +declare function needsNumber(x: number): void; +>needsNumber : Symbol(needsNumber, Decl(negatedTypesControlFlow.ts, 3, 27)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 4, 29)) + +declare function needsString(x: string): void; +>needsString : Symbol(needsString, Decl(negatedTypesControlFlow.ts, 4, 46)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 5, 29)) + +declare function needsObject(x: object): void; +>needsObject : Symbol(needsObject, Decl(negatedTypesControlFlow.ts, 5, 46)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 6, 29)) + +declare var x: ABU; +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 7, 11)) +>ABU : Symbol(ABU, Decl(negatedTypesControlFlow.ts, 2, 64)) + +if (x.type === "a") { +>x.type : Symbol(type, Decl(negatedTypesControlFlow.ts, 0, 13), Decl(negatedTypesControlFlow.ts, 1, 13), Decl(negatedTypesControlFlow.ts, 2, 19)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 7, 11)) +>type : Symbol(type, Decl(negatedTypesControlFlow.ts, 0, 13), Decl(negatedTypesControlFlow.ts, 1, 13), Decl(negatedTypesControlFlow.ts, 2, 19)) + + let y = x.data; +>y : Symbol(y, Decl(negatedTypesControlFlow.ts, 10, 7)) +>x.data : Symbol(A.data, Decl(negatedTypesControlFlow.ts, 0, 24)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 7, 11)) +>data : Symbol(A.data, Decl(negatedTypesControlFlow.ts, 0, 24)) + + needsNumber(y); +>needsNumber : Symbol(needsNumber, Decl(negatedTypesControlFlow.ts, 3, 27)) +>y : Symbol(y, Decl(negatedTypesControlFlow.ts, 10, 7)) +} +else if (x.type === "b") { +>x.type : Symbol(type, Decl(negatedTypesControlFlow.ts, 1, 13), Decl(negatedTypesControlFlow.ts, 2, 19)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 7, 11)) +>type : Symbol(type, Decl(negatedTypesControlFlow.ts, 1, 13), Decl(negatedTypesControlFlow.ts, 2, 19)) + + needsString(x.data); +>needsString : Symbol(needsString, Decl(negatedTypesControlFlow.ts, 4, 46)) +>x.data : Symbol(B.data, Decl(negatedTypesControlFlow.ts, 1, 24)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 7, 11)) +>data : Symbol(B.data, Decl(negatedTypesControlFlow.ts, 1, 24)) +} +else { + needsObject(x.data); +>needsObject : Symbol(needsObject, Decl(negatedTypesControlFlow.ts, 5, 46)) +>x.data : Symbol(Unknown.data, Decl(negatedTypesControlFlow.ts, 2, 49)) +>x : Symbol(x, Decl(negatedTypesControlFlow.ts, 7, 11)) +>data : Symbol(Unknown.data, Decl(negatedTypesControlFlow.ts, 2, 49)) +} + diff --git a/tests/baselines/reference/negatedTypesControlFlow.types b/tests/baselines/reference/negatedTypesControlFlow.types new file mode 100644 index 0000000000000..07041a0f1e059 --- /dev/null +++ b/tests/baselines/reference/negatedTypesControlFlow.types @@ -0,0 +1,72 @@ +=== tests/cases/conformance/types/negated/negatedTypesControlFlow.ts === +interface A { type: "a", data: number } +>type : "a" +>data : number + +interface B { type: "b", data: string } +>type : "b" +>data : string + +interface Unknown { type: string & not ("a"|"b"), data: object } +>type : string & not "a" & not "b" +>data : object + +type ABU = A | B | Unknown; +>ABU : ABU + +declare function needsNumber(x: number): void; +>needsNumber : (x: number) => void +>x : number + +declare function needsString(x: string): void; +>needsString : (x: string) => void +>x : string + +declare function needsObject(x: object): void; +>needsObject : (x: object) => void +>x : object + +declare var x: ABU; +>x : ABU + +if (x.type === "a") { +>x.type === "a" : boolean +>x.type : "a" | "b" | (string & not "a" & not "b") +>x : ABU +>type : "a" | "b" | (string & not "a" & not "b") +>"a" : "a" + + let y = x.data; +>y : number +>x.data : number +>x : A +>data : number + + needsNumber(y); +>needsNumber(y) : void +>needsNumber : (x: number) => void +>y : number +} +else if (x.type === "b") { +>x.type === "b" : boolean +>x.type : "b" | (string & not "a" & not "b") +>x : B | Unknown +>type : "b" | (string & not "a" & not "b") +>"b" : "b" + + needsString(x.data); +>needsString(x.data) : void +>needsString : (x: string) => void +>x.data : string +>x : B +>data : string +} +else { + needsObject(x.data); +>needsObject(x.data) : void +>needsObject : (x: object) => void +>x.data : object +>x : Unknown +>data : object +} + diff --git a/tests/baselines/reference/negatedTypesSimplifyInIntersections.js b/tests/baselines/reference/negatedTypesSimplifyInIntersections.js new file mode 100644 index 0000000000000..54d05dddd639c --- /dev/null +++ b/tests/baselines/reference/negatedTypesSimplifyInIntersections.js @@ -0,0 +1,6 @@ +//// [negatedTypesSimplifyInIntersections.ts] +type A = boolean & not true; // false +type B = "w" & not string; // never + + +//// [negatedTypesSimplifyInIntersections.js] diff --git a/tests/baselines/reference/negatedTypesSimplifyInIntersections.symbols b/tests/baselines/reference/negatedTypesSimplifyInIntersections.symbols new file mode 100644 index 0000000000000..bf0916d406bcb --- /dev/null +++ b/tests/baselines/reference/negatedTypesSimplifyInIntersections.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/types/negated/negatedTypesSimplifyInIntersections.ts === +type A = boolean & not true; // false +>A : Symbol(A, Decl(negatedTypesSimplifyInIntersections.ts, 0, 0)) + +type B = "w" & not string; // never +>B : Symbol(B, Decl(negatedTypesSimplifyInIntersections.ts, 0, 28)) + diff --git a/tests/baselines/reference/negatedTypesSimplifyInIntersections.types b/tests/baselines/reference/negatedTypesSimplifyInIntersections.types new file mode 100644 index 0000000000000..db1113178c263 --- /dev/null +++ b/tests/baselines/reference/negatedTypesSimplifyInIntersections.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/types/negated/negatedTypesSimplifyInIntersections.ts === +type A = boolean & not true; // false +>A : false +>true : true + +type B = "w" & not string; // never +>B : never + diff --git a/tests/baselines/reference/overloadedConstructorFixesInferencesAppropriately.types b/tests/baselines/reference/overloadedConstructorFixesInferencesAppropriately.types index a486c5d20828e..48d04ef11c380 100644 --- a/tests/baselines/reference/overloadedConstructorFixesInferencesAppropriately.types +++ b/tests/baselines/reference/overloadedConstructorFixesInferencesAppropriately.types @@ -46,19 +46,19 @@ function load(): Box<{ success: true } | ErrorResult> { new AsyncLoader({ >new AsyncLoader({ asyncLoad: load, children: result => result.success as any,}) : AsyncLoader >AsyncLoader : typeof AsyncLoader ->{ asyncLoad: load, children: result => result.success as any,} : { asyncLoad: () => Box; children: (result: { success: true; }) => any; } +>{ asyncLoad: load, children: result => result.success as any,} : { asyncLoad: () => Box; children: (result: not ErrorResult & { success: true; }) => any; } asyncLoad: load, >asyncLoad : () => Box >load : () => Box children: result => result.success as any, ->children : (result: { success: true; }) => any ->result => result.success as any : (result: { success: true; }) => any ->result : { success: true; } +>children : (result: not ErrorResult & { success: true; }) => any +>result => result.success as any : (result: not ErrorResult & { success: true; }) => any +>result : not ErrorResult & { success: true; } >result.success as any : any >result.success : true ->result : { success: true; } +>result : not ErrorResult & { success: true; } >success : true }); // should work fine diff --git a/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.errors.txt b/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.errors.txt index 8c7e2f57edaa8..d7ed21438936c 100644 --- a/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.errors.txt +++ b/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.errors.txt @@ -2,37 +2,57 @@ tests/cases/compiler/reactReduxLikeDeferredInferenceAllowsAssignment.ts(76,50): Type 'unknown' is not assignable to type 'Shared>'. Type 'Matching>' is not assignable to type 'Shared>'. Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[P] | (TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[Extract>] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[keyof GetProps & string] | (TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[string] | (TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. - Type 'GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. - Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]) | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[P] | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'GetProps[never] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type '(TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]) | GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] | GetProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type '(TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]) | GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & string] | GetProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. + Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. ==== tests/cases/compiler/reactReduxLikeDeferredInferenceAllowsAssignment.ts (1 errors) ==== @@ -117,37 +137,57 @@ tests/cases/compiler/reactReduxLikeDeferredInferenceAllowsAssignment.ts(76,50): !!! error TS2344: Type 'unknown' is not assignable to type 'Shared>'. !!! error TS2344: Type 'Matching>' is not assignable to type 'Shared>'. !!! error TS2344: Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[P] | (TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[Extract>] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[keyof GetProps & string] | (TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[string] | (TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. -!!! error TS2344: Type 'GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. -!!! error TS2344: Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]) | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[P] | GetProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[P]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string] | TInjectedProps[number] | TInjectedProps[symbol]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'GetProps[never] | (TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'GetProps[never]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type '(Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]) | (Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>])' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]) | GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] | GetProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]) | GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] | GetProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type '(TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]) | GetProps[not keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string] | GetProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type '(TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never) | undefined'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & string] extends GetProps[keyof TInjectedProps & string] ? GetProps[keyof TInjectedProps & string] : TInjectedProps[keyof TInjectedProps & string] : GetProps[not keyof TInjectedProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'keyof GetProps & string extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & keyof GetProps & string] extends GetProps[keyof TInjectedProps & keyof GetProps & string] ? GetProps[keyof TInjectedProps & keyof GetProps & string] : TInjectedProps[keyof TInjectedProps & keyof GetProps & string] : GetProps[not keyof TInjectedProps & keyof GetProps & string]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[keyof TInjectedProps & Extract>] extends GetProps[keyof TInjectedProps & Extract>] ? GetProps[keyof TInjectedProps & Extract>] : TInjectedProps[keyof TInjectedProps & Extract>] : GetProps[not keyof TInjectedProps & Extract>]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'Extract> extends keyof TInjectedProps ? TInjectedProps[Extract>] extends GetProps[Extract>] ? GetProps[Extract>] : TInjectedProps[Extract>] : GetProps[never]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. +!!! error TS2344: Type 'P extends keyof TInjectedProps ? TInjectedProps[P] extends GetProps[P] ? GetProps[P] : TInjectedProps[P] : GetProps[P]' is not assignable to type 'TInjectedProps[P] extends GetProps[P] ? GetProps[P] : never'. >; declare const connect: { diff --git a/tests/cases/conformance/types/conditional/conditionalTypes1.ts b/tests/cases/conformance/types/conditional/conditionalTypes1.ts index 2e8690a228b45..c0e73f7b485eb 100644 --- a/tests/cases/conformance/types/conditional/conditionalTypes1.ts +++ b/tests/cases/conformance/types/conditional/conditionalTypes1.ts @@ -1,6 +1,5 @@ // @strict: true // @declaration: true - type T00 = Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "b" | "d" type T01 = Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">; // "a" | "c" diff --git a/tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts b/tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts new file mode 100644 index 0000000000000..e887c1ee4769f --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedFreshTreatedAsClosedSet.ts @@ -0,0 +1,10 @@ +// from https://github.com/Microsoft/TypeScript/issues/4183 +type Distinct = (A | B) & not (A & B); +declare var o1: {x}; +declare var o2: {y}; + +declare function f1(x: Distinct): void; + +f1({x: 0}); // OK +f1({y: 0}); // OK +f1({x: 0, y: 0}); // Should error diff --git a/tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts b/tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts new file mode 100644 index 0000000000000..5edfecca8b689 --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedInMappedTypeDisablesExcessProperties.ts @@ -0,0 +1,24 @@ +// https://github.com/Microsoft/TypeScript/issues/4196 +// needs https://github.com/Microsoft/TypeScript/pull/26797 to work, as even though the mapped type can be +// written, the key type `string & ~("foo" | "bar")` can't be represented as properties or string/number index +// signatures + +type Config = { + foo: number; + bar: number; +} & { + [k in (string & not ("foo" | "bar"))]: string; +}; + +const conf: Config = { + foo: 12, + bar: 12, + other: "string" +}; // OK + +const conf2: Config = { + foo: 12, + bar: 12, + other: 0, +}; // Should error + diff --git a/tests/cases/conformance/types/negated/negatedPromiseRepr.ts b/tests/cases/conformance/types/negated/negatedPromiseRepr.ts new file mode 100644 index 0000000000000..27d5bd7defc56 --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedPromiseRepr.ts @@ -0,0 +1,52 @@ +// @target: es6 +// inspired by a comment in https://github.com/Microsoft/TypeScript/issues/4196 + +type AnyPromiseLikeObject = object & MyPromiseLike; +interface MyPromiseLike { + then(onResolve: (value: T) => any, onReject: (error: E) => any): any; +} + +type AwaitValue = T extends MyPromiseLike ? U : T; + +type CoercePromiseLike = MyPromise ? AwaitValue : T, never>; + +interface MyPromiseConstructor { + resolve(value: T): CoercePromiseLike; + reject(value: E): MyPromise; + all(values: Iterable): MyPromise[] & not AnyPromiseLikeObject, E>; + race(values: Iterable): MyPromise, E>; +} +declare var MyPromise: MyPromiseConstructor; + +interface MyPromise { + then(onResolve?: not Function, onReject?: not Function): MyPromise; + catch(onReject?: not Function): MyPromise; + then( + onResolve: (value: AwaitValue) => U, + onReject?: not Function, + ): MyPromise, E | F>; + then( + onResolve: not Function, + onReject: (error: E) => U, + ): MyPromise, F>; + then( + onResolve: (value: AwaitValue) => U, + onReject: (error: E) => AwaitValue, + ): MyPromise, F>; + catch( + onReject: (error: E) => U, + ): MyPromise, F>; + finally(onSettled: () => AnyPromiseLikeObject): MyPromise; +} + +const a = MyPromise.resolve(0); + +const b = MyPromise.resolve(MyPromise.resolve(0)); + +const d = MyPromise.resolve(MyPromise.resolve(MyPromise.resolve(0))); + +const e = MyPromise.resolve(0).then(x => "ok"); + +const f = MyPromise.all([1, 2, 3, Promise.resolve("ok")]); + +const g = MyPromise.race([1, 2, 3, Promise.resolve("ok")]); diff --git a/tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts b/tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts new file mode 100644 index 0000000000000..aa505b13dbe04 --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedRepresentativeExamples.ts @@ -0,0 +1,33 @@ +// @strict: true +// https://github.com/Microsoft/TypeScript/issues/7993 + +declare function ignore)>(value: T): void; +declare function readFileAsync(): Promise; +declare function readFileSync(): string; +ignore(readFileSync()); // OK +ignore(readFileAsync()); // Should error + +declare function map(values: T[], map: (value: T) => U) : U[]; // validate map callback doesn't return void + +function foo() {} + +map([1, 2, 3], n => n + 1); // OK +map([1, 2, 3], foo); // Should error + +function asValid(value: T, isValid: (value: T) => boolean) : T | null { + return isValid(value) ? value : null; +} + +declare const x: number; +declare const y: number | null; +asValid(x, n => n >= 0); // OK +asValid(y, n => n >= 0); // Should error + +function tryAt(values: T[], index: number): T | undefined { + return values[index]; +} + +declare const a: number[]; +declare const b: (number | undefined)[]; +tryAt(a, 0); // OK +tryAt(b, 0); // Should error diff --git a/tests/cases/conformance/types/negated/negatedTypeAppliesToFalseBranchOfConditional.ts b/tests/cases/conformance/types/negated/negatedTypeAppliesToFalseBranchOfConditional.ts new file mode 100644 index 0000000000000..b844edcbd2e82 --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedTypeAppliesToFalseBranchOfConditional.ts @@ -0,0 +1,5 @@ +// https://github.com/Microsoft/TypeScript/issues/26240 + +type OnlyNumber = T; +type ToNumber = + T extends string ? undefined : OnlyNumber; diff --git a/tests/cases/conformance/types/negated/negatedTypes.ts b/tests/cases/conformance/types/negated/negatedTypes.ts new file mode 100644 index 0000000000000..e88dab1a8205a --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedTypes.ts @@ -0,0 +1,109 @@ +enum Literal { + ok = "ok" +} + +enum NumLiteral { + Val +} + +function f1( + notString: not string, + str: string, + strlit: "ok", + strenum: Literal, + num: number, + numlit: 0, + numenum: NumLiteral, + unknownVal: unknown, + neverVal: never +) { + notString = str; // not ok + notString = strlit; // not ok + notString = strenum; // not ok + notString = num; // ok + notString = numlit; // ok + notString = numenum; // ok + notString = unknownVal; // not ok (unknown is all values, includes string) + notString = neverVal; // ok (never is empty set of types, doesn't include string) + + str = notString; // not ok + strlit = notString; // not ok + strenum = notString; // not ok + num = notString; // not ok + numlit = notString; // not ok + numenum = notString; // not ok + unknownVal = notString; // ok + neverVal = notString; // not ok +} + +function f2( + x: { x }, + y: { y }, + xy: {x, y}, + nx: not typeof x, + ny: not typeof y, + nxy: not typeof xy, + neither: not (typeof x | typeof y), + notBoth: not (typeof x & typeof y) +) { + x = y; // not ok + x = xy; // ok + x = nx; // not ok + x = ny; // not ok + x = nxy; // not ok + x = neither; // not ok + x = notBoth; // not ok + + y = x; // not ok + y = xy; // ok + y = nx; // not ok + y = ny; // not ok + y = nxy; // not ok + y = neither; // not ok + y = notBoth; // not ok + + xy = x; // not ok + xy = y; // not ok + xy = nx; // not ok + xy = ny; // not ok + xy = nxy; // not ok + xy = neither; // not ok + xy = notBoth; // not ok + + nx = x; // not ok + nx = y; // not ok + nx = ny; // not ok + nx = nxy; // not ok + nx = neither; // ok + nx = notBoth; // not ok + + ny = x; // not ok + ny = y; // not ok + ny = nx; // not ok + ny = nxy; // not ok + ny = neither; // ok + ny = notBoth; // not ok + + nxy = x; // not ok + nxy = y; // not ok + nxy = xy; // not ok + nxy = nx; // ok + nxy = ny; // ok + nxy = neither; // ok + nxy = notBoth; // ok + + neither = x; // not ok + neither = y; // not ok + neither = xy; // not ok + neither = nx; // not ok + neither = ny; // not ok + neither = nxy; // not ok + neither = notBoth; // not ok + + notBoth = x; // not ok + notBoth = y; // not ok + notBoth = xy; // not ok + notBoth = nx; // ok + notBoth = ny; // ok + notBoth = neither; // ok +} \ No newline at end of file diff --git a/tests/cases/conformance/types/negated/negatedTypesControlFlow.ts b/tests/cases/conformance/types/negated/negatedTypesControlFlow.ts new file mode 100644 index 0000000000000..8d4ffb19e3b46 --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedTypesControlFlow.ts @@ -0,0 +1,19 @@ +interface A { type: "a", data: number } +interface B { type: "b", data: string } +interface Unknown { type: string & not ("a"|"b"), data: object } +type ABU = A | B | Unknown; +declare function needsNumber(x: number): void; +declare function needsString(x: string): void; +declare function needsObject(x: object): void; +declare var x: ABU; + +if (x.type === "a") { + let y = x.data; + needsNumber(y); +} +else if (x.type === "b") { + needsString(x.data); +} +else { + needsObject(x.data); +} diff --git a/tests/cases/conformance/types/negated/negatedTypesSimplifyInIntersections.ts b/tests/cases/conformance/types/negated/negatedTypesSimplifyInIntersections.ts new file mode 100644 index 0000000000000..9f9010a892d86 --- /dev/null +++ b/tests/cases/conformance/types/negated/negatedTypesSimplifyInIntersections.ts @@ -0,0 +1,2 @@ +type A = boolean & not true; // false +type B = "w" & not string; // never From 2ef105c446af0f6e96834c5358ee01b8bebb9685 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 5 Jun 2019 15:37:58 -0700 Subject: [PATCH 2/2] Workaround change in how strictly false branches are checked --- src/compiler/checker.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 21d4bfb7e039d..74a82b1cc90e4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26687,7 +26687,18 @@ namespace ts { type PotentiallyUnusedIdentifier = | SourceFile | ModuleDeclaration | ClassLikeDeclaration | InterfaceDeclaration | Block | CaseBlock | ForStatement | ForInStatement | ForOfStatement - | Exclude | TypeAliasDeclaration + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | MethodSignature + | FunctionTypeNode + | ConstructorTypeNode + | FunctionDeclaration + | MethodDeclaration + | ConstructorDeclaration + | AccessorDeclaration + | FunctionExpression + | ArrowFunction + | TypeAliasDeclaration | InferTypeNode; function checkUnusedIdentifiers(potentiallyUnusedIdentifiers: ReadonlyArray, addDiagnostic: AddUnusedDiagnostic) {