diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 4ae35a70bb66e..efa7377a7ef43 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -141,7 +141,7 @@ const ( CachedTypeKindDecoratorContextStatic CachedTypeKindDecoratorContextPrivate CachedTypeKindDecoratorContextPrivateStatic - CachedTypeKindNonDistributedConditionalType + CachedTypeKindNonDistributedType CachedTypeKindSimplifiedConditionalTypeForReading CachedTypeKindSimplifiedConditionalTypeForWriting ) @@ -23898,26 +23898,44 @@ func (c *Checker) getTypeFromTypeReference(node *ast.Node) *Type { func (c *Checker) getDistributedTypeParameter(node *ast.Node, t *Type) *Type { if t.flags&TypeFlagsTypeParameter != 0 && !t.AsTypeParameter().isDistributed && c.isInDistributiveContext(node, t.symbol) { - // If node is contained in a distributive conditional type for the given type parameter, + // If node is contained in a distributive context for the given type parameter, // return the distributed form of the type parameter. return c.getDistributedTypeFromTypeParameter(t) } return t } -// Returns true if the node is, or is contained in, a distributive conditional type for the given type -// parameter symbol, or for any type parameter when symbol is nil. Types declared in such a context may -// reference distributed type parameters, so their identity instantiation isn't the declared type itself -// (instantiation maps distributed type parameters back to their non-distributed form). +// Returns true if the node is, or is contained in, a distributive context for the given type parameter +// symbol, or for any type parameter when symbol is nil. A distributive context is a distributive conditional +// type 'T extends U ? X : Y' or the template of a homomorphic mapped type '{ [K in keyof T]: X }', both of +// which distribute over union types for T. Types declared in such a context may reference distributed type +// parameters, so their identity instantiation isn't the declared type itself (instantiation maps distributed +// type parameters back to their non-distributed form). func (c *Checker) isInDistributiveContext(node *ast.Node, symbol *ast.Symbol) bool { - for n := node; n != nil && !ast.IsStatement(n); n = n.Parent { - if ast.IsConditionalTypeNode(n) { - if checkTypeNode := n.AsConditionalTypeNode().CheckType; isSimpleIdentifierTypeReference(checkTypeNode) { - if s := c.getSymbolFromTypeReference(checkTypeNode); s != nil && s.Flags()&ast.SymbolFlagsTypeParameter != 0 && (symbol == nil || s == symbol) { - return true + var child *ast.Node + for n := node; n != nil && !ast.IsStatement(n); child, n = n, n.Parent { + var typeParameterNode *ast.Node + switch { + case ast.IsConditionalTypeNode(n): + typeParameterNode = ast.SkipTypeParentheses(n.AsConditionalTypeNode().CheckType) + case ast.IsMappedTypeNode(n): + // The template and name type of a homomorphic mapped type are distributive contexts, but its + // 'keyof T' constraint is not: the constraint of the mapped type's type parameter is shared by + // all instantiations of the mapped type and must stay in terms of the non-distributed form. + m := n.AsMappedTypeNode() + if child == nil || child == m.Type || child == m.NameType { + if constraint := m.TypeParameter.AsTypeParameterDeclaration().Constraint; constraint != nil { + if constraint := ast.SkipTypeParentheses(constraint); ast.IsTypeOperatorNode(constraint) && constraint.AsTypeOperatorNode().Operator == ast.KindKeyOfKeyword { + typeParameterNode = ast.SkipTypeParentheses(constraint.Type()) + } } } } + if typeParameterNode != nil && isSimpleIdentifierTypeReference(typeParameterNode) { + if s := c.getSymbolFromTypeReference(typeParameterNode); s != nil && s.Flags()&ast.SymbolFlagsTypeParameter != 0 && (symbol == nil || s == symbol) { + return true + } + } } return false } @@ -23933,20 +23951,51 @@ func (c *Checker) getDistributedTypeFromTypeParameter(t *Type) *Type { } // Returns the given conditional type with references to the distributed form of its check type parameter -// mapped back to the non-distributed form. This is the identity instantiation of the conditional type, -// which is cached in the instantiation map of the conditional type's root. +// mapped back to the non-distributed form. func (c *Checker) getNonDistributedConditionalType(t *Type) *Type { - checkType := t.AsConditionalType().checkType - typeParameter := getNonDistributedTypeParameter(checkType) - if typeParameter == checkType { + result := c.getNonDistributedType(t, t.AsConditionalType().checkType) + debug.Assert(result.flags&TypeFlagsConditional != 0, "Identity instantiation of a conditional type should remain deferred") + return result +} + +// Returns the given generic mapped type with references to the distributed form of its homomorphic type +// variable mapped back to the non-distributed form. Only declared mapped types need this, as instantiation +// already maps distributed type parameters back to their non-distributed form. A type variable that is itself +// distributed comes from an enclosing distributive context and must keep its distributed form. +func (c *Checker) getNonDistributedMappedType(t *Type) *Type { + if t.AsMappedType().target != nil { return t } - key := CachedTypeKey{kind: CachedTypeKindNonDistributedConditionalType, typeId: t.id} + constraintType := c.getConstraintTypeFromMappedType(t) + if constraintType.flags&TypeFlagsIndex == 0 { + return t + } + typeVariable := constraintType.AsIndexType().target + if typeVariable.flags&TypeFlagsSubstitution != 0 { + typeVariable = typeVariable.AsSubstitutionType().baseType + } + if typeVariable.flags&TypeFlagsTypeParameter == 0 || typeVariable.AsTypeParameter().isDistributed { + return t + } + result := c.getNonDistributedType(t, c.getDistributedTypeFromTypeParameter(typeVariable)) + debug.Assert(result.objectFlags&ObjectFlagsMapped != 0, "Identity instantiation of a generic mapped type should remain a mapped type") + return result +} + +// Returns the identity instantiation of the given type for the non-distributed form of the given type +// variable if it is a distributed type parameter, and otherwise the type itself. Instantiation maps all +// occurrences of distributed type parameters back to their non-distributed form, so the result is the +// given type with distributed type parameters replaced by their non-distributed form. +func (c *Checker) getNonDistributedType(t *Type, typeVariable *Type) *Type { + typeParameter := getNonDistributedTypeParameter(typeVariable) + if typeParameter == typeVariable { + return t + } + key := CachedTypeKey{kind: CachedTypeKindNonDistributedType, typeId: t.id} if cached := c.cachedTypes[key]; cached != nil { return cached } result := c.instantiateType(t, newSimpleTypeMapper(typeParameter, typeParameter)) - debug.Assert(result.flags&TypeFlagsConditional != 0, "Identity instantiation of a conditional type should remain deferred") c.cachedTypes[key] = result return result } diff --git a/tsc/internal/checker/inference.go b/tsc/internal/checker/inference.go index 4cf926f2dc8ad..7ccc4f21978b3 100644 --- a/tsc/internal/checker/inference.go +++ b/tsc/internal/checker/inference.go @@ -699,6 +699,7 @@ func (c *Checker) inferToTemplateLiteralType(n *InferenceState, source *Type, ta func (c *Checker) inferFromGenericMappedTypes(n *InferenceState, source *Type, target *Type) { // The source and target types are generic types { [P in S]: X } and { [P in T]: Y }, so we infer // from S to T and from X to Y. + source = c.getNonDistributedMappedType(source) c.inferFromTypes(n, c.getConstraintTypeFromMappedType(source), c.getConstraintTypeFromMappedType(target)) c.inferFromTypes(n, c.getTemplateTypeFromMappedType(source), c.getTemplateTypeFromMappedType(target)) sourceNameType := c.getNameTypeFromMappedType(source) @@ -970,7 +971,7 @@ func (c *Checker) inferToMappedType(n *InferenceState, source *Type, target *Typ // where T is a type variable. Use inferTypeForHomomorphicMappedType to infer a suitable source // type and then make a secondary inference from that type to T. We make a secondary inference // such that direct inferences to T get priority over inferences to Partial, for example. - inference := getInferenceInfoForType(n, constraintType.AsIndexType().target) + inference := getInferenceInfoForType(n, c.getActualTypeVariable(constraintType.AsIndexType().target)) if inference != nil && !inference.isFixed && !c.isFromInferenceBlockedSource(source) { inferredType := c.inferTypeForHomomorphicMappedType(source, target, constraintType) if inferredType != nil { @@ -1101,7 +1102,7 @@ func (c *Checker) inferReverseMappedType(source *Type, target *Type, constraint } func (c *Checker) inferReverseMappedTypeWorker(source *Type, target *Type, constraint *Type) *Type { - typeParameter := c.getIndexedAccessType(constraint.AsIndexType().target, c.getTypeParameterFromMappedType(target)) + typeParameter := c.getIndexedAccessType(c.getActualTypeVariable(constraint.AsIndexType().target), c.getTypeParameterFromMappedType(target)) templateType := c.getTemplateTypeFromMappedType(target) inference := newInferenceInfo(typeParameter) c.inferTypes([]*InferenceInfo{inference}, source, templateType, InferencePriorityNone, false) @@ -1196,7 +1197,10 @@ func (c *Checker) replaceIndexedAccess(instantiable *Type, t *Type, replacement // map type.indexType to 0 // map type.objectType to `[TReplacement]` // thus making the indexed access `[TReplacement][0]` or `TReplacement` - return c.instantiateType(instantiable, newTypeMapper([]*Type{t.AsIndexedAccessType().indexType, t.AsIndexedAccessType().objectType}, []*Type{c.getNumberLiteralType(0), c.createTupleType([]*Type{replacement})})) + // Mappers look up distributed type parameters by their non-distributed form, so the sources must use that form too. + indexType := getNonDistributedTypeParameter(t.AsIndexedAccessType().indexType) + objectType := getNonDistributedTypeParameter(t.AsIndexedAccessType().objectType) + return c.instantiateType(instantiable, newTypeMapper([]*Type{indexType, objectType}, []*Type{c.getNumberLiteralType(0), c.createTupleType([]*Type{replacement})})) } func (c *Checker) typesDefinitelyUnrelated(source *Type, target *Type) bool { diff --git a/tsc/internal/checker/relater.go b/tsc/internal/checker/relater.go index ed0f275064ac2..638f9889ec8d0 100644 --- a/tsc/internal/checker/relater.go +++ b/tsc/internal/checker/relater.go @@ -3655,6 +3655,7 @@ func (r *Relater) structuredTypeRelatedToWorker(source *Type, target *Type, repo } case r.c.isGenericMappedType(target) && r.relation != r.c.identityRelation: // Check if source type `S` is related to target type `{ [P in Q]: T }` or `{ [P in Q as R]: T}`. + target := r.c.getNonDistributedMappedType(target) keysRemapped := target.AsMappedType().declaration.NameType != nil templateType := r.c.getTemplateTypeFromMappedType(target) modifiers := getMappedTypeModifiers(target) @@ -4042,6 +4043,11 @@ func (r *Relater) mappedTypeRelatedTo(source *Type, target *Type, reportErrors b r.relation == r.c.identityRelation && getMappedTypeModifiers(source) == getMappedTypeModifiers(target) || r.relation != r.c.identityRelation && r.c.getCombinedMappedTypeOptionality(source) <= r.c.getCombinedMappedTypeOptionality(target) if modifiersRelated { + // The constituent types of a homomorphic mapped type reference the distributed form of its type + // variable. The source constituents are instantiated below, which maps them back to the non-distributed + // form, but the target ones are related as is, so normalize the target to make the comparison not + // depend on whether it has been instantiated. + target := r.c.getNonDistributedMappedType(target) targetConstraint := r.c.getConstraintTypeFromMappedType(target) sourceConstraint := r.c.instantiateType(r.c.getConstraintTypeFromMappedType(source), core.IfElse(r.c.getCombinedMappedTypeOptionality(source) < 0, r.c.reportUnmeasurableMapper, r.c.reportUnreliableMapper)) if result := r.isRelatedTo(targetConstraint, sourceConstraint, RecursionFlagsBoth, reportErrors); result != TernaryFalse { @@ -4656,7 +4662,7 @@ func (r *Relater) indexSignaturesRelatedTo(source *Type, target *Type, sourceIsP case r.relation != r.c.strictSubtypeRelation && !sourceIsPrimitive && targetHasStringIndex && targetInfo.valueType.flags&TypeFlagsAny != 0: related = TernaryTrue case r.c.isGenericMappedType(source) && targetHasStringIndex: - related = r.isRelatedTo(r.c.getTemplateTypeFromMappedType(source), targetInfo.valueType, RecursionFlagsBoth, reportErrors) + related = r.isRelatedTo(r.c.getTemplateTypeFromMappedType(r.c.getNonDistributedMappedType(source)), targetInfo.valueType, RecursionFlagsBoth, reportErrors) default: related = r.typeRelatedToIndexInfo(source, targetInfo, reportErrors, intersectionState) } diff --git a/tsc/internal/fourslash/tests/quickInfoDistributedTypeParameter_test.go b/tsc/internal/fourslash/tests/quickInfoDistributedTypeParameter_test.go index e29c90852030c..ae1ba5d6849ca 100644 --- a/tsc/internal/fourslash/tests/quickInfoDistributedTypeParameter_test.go +++ b/tsc/internal/fourslash/tests/quickInfoDistributedTypeParameter_test.go @@ -15,6 +15,10 @@ func TestQuickInfoDistributedTypeParameter(t *testing.T) { ? T/*trueType*/ : T/*falseType*/; +type Mapped = { [P in keyof T/*mappedConstraint*/]: T/*mappedType*/ }; + +type MappedAs = { [P in keyof T as T/*mappedNameType*/ extends unknown ? P : never]: T }; + type NonDistributed = [T/*nonDistributed*/] extends [unknown] ? T : never;` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) defer done() @@ -22,5 +26,8 @@ type NonDistributed = [T/*nonDistributed*/] extends [unknown] ? T : never;` f.VerifyQuickInfoAt(t, "extends", "(type parameter) (distributed) T in type Conditional", "") f.VerifyQuickInfoAt(t, "trueType", "(type parameter) (distributed) T in type Conditional", "") f.VerifyQuickInfoAt(t, "falseType", "(type parameter) (distributed) T in type Conditional", "") + f.VerifyQuickInfoAt(t, "mappedConstraint", "(type parameter) T in type Mapped", "") + f.VerifyQuickInfoAt(t, "mappedType", "(type parameter) (distributed) T in type Mapped", "") + f.VerifyQuickInfoAt(t, "mappedNameType", "(type parameter) (distributed) T in type MappedAs", "") f.VerifyQuickInfoAt(t, "nonDistributed", "(type parameter) T in type NonDistributed", "") } diff --git a/tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.symbols b/tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.symbols new file mode 100644 index 0000000000000..ed627147c7571 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.symbols @@ -0,0 +1,67 @@ +//// [tests/cases/compiler/distributedMappedTypeIndexSignature.ts] //// + +=== distributedMappedTypeIndexSignature.ts === +type Alias = { [K in keyof T]: (state: T) => void }; +>Alias : Symbol(Alias, Decl(distributedMappedTypeIndexSignature.ts, 0, 0)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 0, 11)) +>K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 0, 19)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 0, 11)) +>state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 0, 35)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 0, 11)) + +type Check void }> = X; +>Check : Symbol(Check, Decl(distributedMappedTypeIndexSignature.ts, 0, 55)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 1, 11)) +>X : Symbol(X, Decl(distributedMappedTypeIndexSignature.ts, 1, 13)) +>x : Symbol(x, Decl(distributedMappedTypeIndexSignature.ts, 1, 27)) +>state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 1, 40)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 1, 11)) +>X : Symbol(X, Decl(distributedMappedTypeIndexSignature.ts, 1, 13)) + +type Use1 = Check>; +>Use1 : Symbol(Use1, Decl(distributedMappedTypeIndexSignature.ts, 1, 65)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 2, 10)) +>Check : Symbol(Check, Decl(distributedMappedTypeIndexSignature.ts, 0, 55)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 2, 10)) +>Alias : Symbol(Alias, Decl(distributedMappedTypeIndexSignature.ts, 0, 0)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 2, 10)) + +type Use2 = Check void }>; +>Use2 : Symbol(Use2, Decl(distributedMappedTypeIndexSignature.ts, 2, 34)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) +>Check : Symbol(Check, Decl(distributedMappedTypeIndexSignature.ts, 0, 55)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) +>K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 3, 27)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) +>state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 3, 43)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 3, 10)) + +function f(alias: Alias, inline: { [K in keyof T]: (state: T) => T[K] }) { +>f : Symbol(f, Decl(distributedMappedTypeIndexSignature.ts, 3, 64)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) +>alias : Symbol(alias, Decl(distributedMappedTypeIndexSignature.ts, 5, 14)) +>Alias : Symbol(Alias, Decl(distributedMappedTypeIndexSignature.ts, 0, 0)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) +>inline : Symbol(inline, Decl(distributedMappedTypeIndexSignature.ts, 5, 30)) +>K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 5, 42)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) +>state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 5, 58)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) +>K : Symbol(K, Decl(distributedMappedTypeIndexSignature.ts, 5, 42)) + + const a: Record unknown> = alias; +>a : Symbol(a, Decl(distributedMappedTypeIndexSignature.ts, 6, 9)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 6, 29)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) +>alias : Symbol(alias, Decl(distributedMappedTypeIndexSignature.ts, 5, 14)) + + const b: Record unknown> = inline; +>b : Symbol(b, Decl(distributedMappedTypeIndexSignature.ts, 7, 9)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>state : Symbol(state, Decl(distributedMappedTypeIndexSignature.ts, 7, 29)) +>T : Symbol(T, Decl(distributedMappedTypeIndexSignature.ts, 5, 11)) +>inline : Symbol(inline, Decl(distributedMappedTypeIndexSignature.ts, 5, 30)) +} + diff --git a/tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.types b/tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.types new file mode 100644 index 0000000000000..5625d051bac99 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/distributedMappedTypeIndexSignature.types @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/distributedMappedTypeIndexSignature.ts] //// + +=== distributedMappedTypeIndexSignature.ts === +type Alias = { [K in keyof T]: (state: T) => void }; +>Alias : Alias +>state : T + +type Check void }> = X; +>Check : X +>x : string +>state : T + +type Use1 = Check>; +>Use1 : Alias + +type Use2 = Check void }>; +>Use2 : { [K in keyof T]: (state: T) => void; } +>state : T + +function f(alias: Alias, inline: { [K in keyof T]: (state: T) => T[K] }) { +>f : (alias: Alias, inline: { [K in keyof T]: (state: T) => T[K]; }) => void +>alias : Alias +>inline : { [K in keyof T]: (state: T) => T[K]; } +>state : T + + const a: Record unknown> = alias; +>a : Record unknown> +>state : T +>alias : Alias + + const b: Record unknown> = inline; +>b : Record unknown> +>state : T +>inline : { [K in keyof T]: (state: T) => T[K]; } +} + diff --git a/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.errors.txt b/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.errors.txt index f254863e4a6e3..f20a35cb98818 100644 --- a/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.errors.txt @@ -14,9 +14,52 @@ distributedTypeParameters.ts(56,15): error TS2344: Type 'C' does not satisfy the 'C' is only assignable to the non-distributed 'A', but 'A' has been distributed here. distributedTypeParameters.ts(57,15): error TS2344: Type 'C' does not satisfy the constraint 'B'. 'C' is only assignable to the non-distributed 'B', but 'B' has been distributed here. +distributedTypeParameters.ts(66,27): error TS2344: Type 'B' does not satisfy the constraint 'A'. + 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. +distributedTypeParameters.ts(70,32): error TS2344: Type 'B' does not satisfy the constraint 'A'. + 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. +distributedTypeParameters.ts(83,46): error TS2344: Type 'U[keyof T]' does not satisfy the constraint 'T[keyof T]'. + Type 'U' is not assignable to type 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParameters.ts(83,46): error TS2536: Type 'keyof T' cannot be used to index type 'U'. +distributedTypeParameters.ts(91,36): error TS2344: Type 'U[P]' does not satisfy the constraint 'T[P]'. + Type 'U' is not assignable to type 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParameters.ts(134,35): error TS2344: Type 'I[K]' does not satisfy the constraint 'P[K]'. + Type 'I' is not assignable to type 'P'. + 'I' is only assignable to the non-distributed 'P', but 'P' has been distributed here. +distributedTypeParameters.ts(134,35): error TS2536: Type 'K' cannot be used to index type 'I'. +distributedTypeParameters.ts(143,64): error TS2344: Type 'U' does not satisfy the constraint 'Mutable'. + Type 'T' is not assignable to type 'Mutable'. +distributedTypeParameters.ts(144,64): error TS2344: Type 'U' does not satisfy the constraint 'Partial'. + Type 'T' is not assignable to type 'Partial'. +distributedTypeParameters.ts(145,64): error TS2344: Type 'Mutable' does not satisfy the constraint 'Mutable'. + Type 'keyof T' is not assignable to type 'keyof U'. + Type 'string | number | symbol' is not assignable to type 'keyof U'. + Type 'string' is not assignable to type 'keyof U'. + Type 'string' is not assignable to type 'keyof T'. + Type 'keyof T' is not assignable to type 'keyof T'. Two different types with this name exist, but they are unrelated. + Type 'string | number | symbol' is not assignable to type 'keyof T'. + Type 'string' is not assignable to type 'keyof T'. +distributedTypeParameters.ts(146,78): error TS2344: Type 'U' does not satisfy the constraint '{ [K in keyof T]: T[K]; }'. + Type 'T' is not assignable to type '{ [K in keyof T]: T[K]; }'. +distributedTypeParameters.ts(147,62): error TS2344: Type 'U' does not satisfy the constraint 'Mutable'. + Type 'T' is not assignable to type 'Mutable'. +distributedTypeParameters.ts(159,71): error TS2344: Type 'B' does not satisfy the constraint 'A'. + 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. +distributedTypeParameters.ts(160,71): error TS2344: Type 'B' does not satisfy the constraint 'A'. + 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. +distributedTypeParameters.ts(161,66): error TS2344: Type 'C' does not satisfy the constraint 'A'. + 'C' is only assignable to the non-distributed 'A', but 'A' has been distributed here. +distributedTypeParameters.ts(162,85): error TS2344: Type 'C' does not satisfy the constraint 'A'. + 'C' is only assignable to the non-distributed 'A', but 'A' has been distributed here. +distributedTypeParameters.ts(162,97): error TS2344: Type 'C' does not satisfy the constraint 'B'. + 'C' is only assignable to the non-distributed 'B', but 'B' has been distributed here. +distributedTypeParameters.ts(163,54): error TS2344: Type 'B' does not satisfy the constraint 'A'. + 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. -==== distributedTypeParameters.ts (8 errors) ==== +==== distributedTypeParameters.ts (26 errors) ==== // https://github.com/microsoft/TypeScript/issues/63708 type Show = [A, B] & {}; @@ -105,6 +148,56 @@ distributedTypeParameters.ts(57,15): error TS2344: Type 'C' does not satisfy the Show : never; + type M1 = { + [K in keyof A]: Show; // Error + ~ +!!! error TS2344: Type 'B' does not satisfy the constraint 'A'. +!!! error TS2344: 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. + }; + + type M2 = { + [K in keyof A as K]: Show; // Error + ~ +!!! error TS2344: Type 'B' does not satisfy the constraint 'A'. +!!! error TS2344: 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. + }; + + type M3 = { + [K in keyof A & string]: Show; + }; + + type X5 = M1<{ a: 0 } | { b: 1 }, { a: 0 }>; + type X6 = M2<{ a: 0 } | { b: 1 }, { a: 0 }>; + + type ShowResult = U extends T ? true : false; + + declare function conditionalIndexedAccess(y: U): + T extends unknown ? ShowResult : never; // Error + ~~~~~~~~~~ +!!! error TS2344: Type 'U[keyof T]' does not satisfy the constraint 'T[keyof T]'. +!!! error TS2344: Type 'U' is not assignable to type 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + ~~~~~~~~~~ +!!! error TS2536: Type 'keyof T' cannot be used to index type 'U'. + + const conditionalIndexedAccessResult = conditionalIndexedAccess< + { a: 1 } | { b: 2 }, + { a: 1 } + >({ a: 1 }); + + declare function mappedIndexedAccess(y: U): { + [P in keyof T]: ShowResult; // Error + ~~~~ +!!! error TS2344: Type 'U[P]' does not satisfy the constraint 'T[P]'. +!!! error TS2344: Type 'U' is not assignable to type 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + }; + + const mappedIndexedAccessResult = mappedIndexedAccess< + { a: 1 } | { b: 2 }, + { a: 1 } + >({ a: 1 }); + // Ensure mapped type modifiers are computed correctly, example from type-fest type IsReadonlyKeyOf = @@ -135,4 +228,89 @@ distributedTypeParameters.ts(57,15): error TS2344: Type 'C' does not satisfy the type T10 = IsReadonlyKeyOf<{ a: string }, 'a'>; // false type T11 = IsReadonlyKeyOf<{ readonly b: string }, 'b'>; // true + + // Repro from triggerdotdev/trigger.dev + + type Exact = + P extends unknown ? + { [K in keyof P]: Exact } : // Error + ~~~~ +!!! error TS2344: Type 'I[K]' does not satisfy the constraint 'P[K]'. +!!! error TS2344: Type 'I' is not assignable to type 'P'. +!!! error TS2344: 'I' is only assignable to the non-distributed 'P', but 'P' has been distributed here. + ~~~~ +!!! error TS2536: Type 'K' cannot be used to index type 'I'. + never; + + type X7 = Exact<{ a: 0 } | { b: 1 }, { a: 0 }>; + + // Homomorphic mapped types instantiated for a distributed type parameter keep its distributed form + + type Mutable = { -readonly [K in keyof T]: T[K] }; + + type C1 = T extends unknown ? Show, U> : never; // Error + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'Mutable'. +!!! error TS2344: Type 'T' is not assignable to type 'Mutable'. +!!! related TS2208 distributedTypeParameters.ts:143:9: This type parameter might need an `extends Mutable` constraint. + type C2 = T extends unknown ? Show, U> : never; // Error + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'Partial'. +!!! error TS2344: Type 'T' is not assignable to type 'Partial'. +!!! related TS2208 distributedTypeParameters.ts:144:9: This type parameter might need an `extends Partial` constraint. + type C3 = T extends unknown ? Show, Mutable> : never; // Error + ~~~~~~~~~~ +!!! error TS2344: Type 'Mutable' does not satisfy the constraint 'Mutable'. +!!! error TS2344: Type 'keyof T' is not assignable to type 'keyof U'. +!!! error TS2344: Type 'string | number | symbol' is not assignable to type 'keyof U'. +!!! error TS2344: Type 'string' is not assignable to type 'keyof U'. +!!! error TS2344: Type 'string' is not assignable to type 'keyof T'. +!!! error TS2344: Type 'keyof T' is not assignable to type 'keyof T'. Two different types with this name exist, but they are unrelated. +!!! error TS2344: Type 'string | number | symbol' is not assignable to type 'keyof T'. +!!! error TS2344: Type 'string' is not assignable to type 'keyof T'. + type C4 = T extends unknown ? Show<{ [K in keyof T]: T[K] }, U> : never; // Error + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint '{ [K in keyof T]: T[K]; }'. +!!! error TS2344: Type 'T' is not assignable to type '{ [K in keyof T]: T[K]; }'. +!!! related TS2208 distributedTypeParameters.ts:146:9: This type parameter might need an `extends { [K in keyof T]: T[K]; }` constraint. + type M4 = { [K in keyof T]: Show, U> }; // Error + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'Mutable'. +!!! error TS2344: Type 'T' is not assignable to type 'Mutable'. +!!! related TS2208 distributedTypeParameters.ts:147:9: This type parameter might need an `extends Mutable` constraint. + + // Normalization doesn't depend on whether the template was resolved before + + declare function inferFromMappedGetter(u: { [K in keyof U]: () => U }): () => U; + + function f1(getter: () => T) { + let r = inferFromMappedGetter(get()); + r = getter; + function get(): { [K in keyof T]: () => T } { return null!; } + } + + type M5 = { [K in keyof A]: { [J in keyof B]: Show } }; + ~ +!!! error TS2344: Type 'B' does not satisfy the constraint 'A'. +!!! error TS2344: 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. + type M6 = { [K in keyof B]: { [J in keyof A]: Show } }; + ~ +!!! error TS2344: Type 'B' does not satisfy the constraint 'A'. +!!! error TS2344: 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. + type M7 = { [K in keyof A]: Show }; + ~ +!!! error TS2344: Type 'C' does not satisfy the constraint 'A'. +!!! error TS2344: 'C' is only assignable to the non-distributed 'A', but 'A' has been distributed here. + type M8 = { [K in keyof A]: { [J in keyof B]: [Show, Show] } }; + ~ +!!! error TS2344: Type 'C' does not satisfy the constraint 'A'. +!!! error TS2344: 'C' is only assignable to the non-distributed 'A', but 'A' has been distributed here. + ~ +!!! error TS2344: Type 'C' does not satisfy the constraint 'B'. +!!! error TS2344: 'C' is only assignable to the non-distributed 'B', but 'B' has been distributed here. + type M9 = { [K in keyof A as Show extends never ? never : K]: 0 }; + ~ +!!! error TS2344: Type 'B' does not satisfy the constraint 'A'. +!!! error TS2344: 'B' is only assignable to the non-distributed 'A', but 'A' has been distributed here. + type M10 = { [K in keyof [A]]: Show }; \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.symbols b/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.symbols index 4d04f842c3e63..a6bb6c4e166c0 100644 --- a/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.symbols +++ b/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.symbols @@ -206,100 +206,442 @@ type T5 = never; +type M1 = { +>M1 : Symbol(M1, Decl(distributedTypeParameters.ts, 62, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 64, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 64, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 64, 8)) + + [K in keyof A]: Show; // Error +>K : Symbol(K, Decl(distributedTypeParameters.ts, 65, 3)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 64, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 64, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 64, 10)) + +}; + +type M2 = { +>M2 : Symbol(M2, Decl(distributedTypeParameters.ts, 66, 2)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 68, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 68, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 68, 8)) + + [K in keyof A as K]: Show; // Error +>K : Symbol(K, Decl(distributedTypeParameters.ts, 69, 3)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 68, 8)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 69, 3)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 68, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 68, 10)) + +}; + +type M3 = { +>M3 : Symbol(M3, Decl(distributedTypeParameters.ts, 70, 2)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 72, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 72, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 72, 8)) + + [K in keyof A & string]: Show; +>K : Symbol(K, Decl(distributedTypeParameters.ts, 73, 3)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 72, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 72, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 72, 10)) + +}; + +type X5 = M1<{ a: 0 } | { b: 1 }, { a: 0 }>; +>X5 : Symbol(X5, Decl(distributedTypeParameters.ts, 74, 2)) +>M1 : Symbol(M1, Decl(distributedTypeParameters.ts, 62, 10)) +>a : Symbol(a, Decl(distributedTypeParameters.ts, 76, 14)) +>b : Symbol(b, Decl(distributedTypeParameters.ts, 76, 25)) +>a : Symbol(a, Decl(distributedTypeParameters.ts, 76, 35)) + +type X6 = M2<{ a: 0 } | { b: 1 }, { a: 0 }>; +>X6 : Symbol(X6, Decl(distributedTypeParameters.ts, 76, 44)) +>M2 : Symbol(M2, Decl(distributedTypeParameters.ts, 66, 2)) +>a : Symbol(a, Decl(distributedTypeParameters.ts, 77, 14)) +>b : Symbol(b, Decl(distributedTypeParameters.ts, 77, 25)) +>a : Symbol(a, Decl(distributedTypeParameters.ts, 77, 35)) + +type ShowResult = U extends T ? true : false; +>ShowResult : Symbol(ShowResult, Decl(distributedTypeParameters.ts, 77, 44)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 79, 16)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 79, 18)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 79, 16)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 79, 18)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 79, 16)) + +declare function conditionalIndexedAccess(y: U): +>conditionalIndexedAccess : Symbol(conditionalIndexedAccess, Decl(distributedTypeParameters.ts, 79, 61)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 81, 42)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 81, 44)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 81, 42)) +>y : Symbol(y, Decl(distributedTypeParameters.ts, 81, 58)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 81, 44)) + + T extends unknown ? ShowResult : never; // Error +>T : Symbol(T, Decl(distributedTypeParameters.ts, 81, 42)) +>ShowResult : Symbol(ShowResult, Decl(distributedTypeParameters.ts, 77, 44)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 81, 42)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 81, 42)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 81, 44)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 81, 42)) + +const conditionalIndexedAccessResult = conditionalIndexedAccess< +>conditionalIndexedAccessResult : Symbol(conditionalIndexedAccessResult, Decl(distributedTypeParameters.ts, 84, 5)) +>conditionalIndexedAccess : Symbol(conditionalIndexedAccess, Decl(distributedTypeParameters.ts, 79, 61)) + + { a: 1 } | { b: 2 }, +>a : Symbol(a, Decl(distributedTypeParameters.ts, 85, 3)) +>b : Symbol(b, Decl(distributedTypeParameters.ts, 85, 14)) + + { a: 1 } +>a : Symbol(a, Decl(distributedTypeParameters.ts, 86, 3)) + +>({ a: 1 }); +>a : Symbol(a, Decl(distributedTypeParameters.ts, 87, 3)) + +declare function mappedIndexedAccess(y: U): { +>mappedIndexedAccess : Symbol(mappedIndexedAccess, Decl(distributedTypeParameters.ts, 87, 12)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 89, 37)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 89, 39)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 89, 37)) +>y : Symbol(y, Decl(distributedTypeParameters.ts, 89, 53)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 89, 39)) + + [P in keyof T]: ShowResult; // Error +>P : Symbol(P, Decl(distributedTypeParameters.ts, 90, 3)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 89, 37)) +>ShowResult : Symbol(ShowResult, Decl(distributedTypeParameters.ts, 77, 44)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 89, 37)) +>P : Symbol(P, Decl(distributedTypeParameters.ts, 90, 3)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 89, 39)) +>P : Symbol(P, Decl(distributedTypeParameters.ts, 90, 3)) + +}; + +const mappedIndexedAccessResult = mappedIndexedAccess< +>mappedIndexedAccessResult : Symbol(mappedIndexedAccessResult, Decl(distributedTypeParameters.ts, 93, 5)) +>mappedIndexedAccess : Symbol(mappedIndexedAccess, Decl(distributedTypeParameters.ts, 87, 12)) + + { a: 1 } | { b: 2 }, +>a : Symbol(a, Decl(distributedTypeParameters.ts, 94, 3)) +>b : Symbol(b, Decl(distributedTypeParameters.ts, 94, 14)) + + { a: 1 } +>a : Symbol(a, Decl(distributedTypeParameters.ts, 95, 3)) + +>({ a: 1 }); +>a : Symbol(a, Decl(distributedTypeParameters.ts, 96, 3)) + // Ensure mapped type modifiers are computed correctly, example from type-fest type IsReadonlyKeyOf = ->IsReadonlyKeyOf : Symbol(IsReadonlyKeyOf, Decl(distributedTypeParameters.ts, 62, 10)) ->Type : Symbol(Type, Decl(distributedTypeParameters.ts, 66, 21)) ->Key : Symbol(Key, Decl(distributedTypeParameters.ts, 66, 41)) ->Type : Symbol(Type, Decl(distributedTypeParameters.ts, 66, 21)) +>IsReadonlyKeyOf : Symbol(IsReadonlyKeyOf, Decl(distributedTypeParameters.ts, 96, 12)) +>Type : Symbol(Type, Decl(distributedTypeParameters.ts, 100, 21)) +>Key : Symbol(Key, Decl(distributedTypeParameters.ts, 100, 41)) +>Type : Symbol(Type, Decl(distributedTypeParameters.ts, 100, 21)) IsAny extends true ? never ->IsAny : Symbol(IsAny, Decl(distributedTypeParameters.ts, 75, 11)) ->Type : Symbol(Type, Decl(distributedTypeParameters.ts, 66, 21)) ->Key : Symbol(Key, Decl(distributedTypeParameters.ts, 66, 41)) +>IsAny : Symbol(IsAny, Decl(distributedTypeParameters.ts, 109, 11)) +>Type : Symbol(Type, Decl(distributedTypeParameters.ts, 100, 21)) +>Key : Symbol(Key, Decl(distributedTypeParameters.ts, 100, 41)) : Key extends unknown // For distributing `Key` ->Key : Symbol(Key, Decl(distributedTypeParameters.ts, 66, 41)) +>Key : Symbol(Key, Decl(distributedTypeParameters.ts, 100, 41)) ? Type extends unknown // For distributing `Type` ->Type : Symbol(Type, Decl(distributedTypeParameters.ts, 66, 21)) +>Type : Symbol(Type, Decl(distributedTypeParameters.ts, 100, 21)) ? IsEqual< ->IsEqual : Symbol(IsEqual, Decl(distributedTypeParameters.ts, 77, 56)) +>IsEqual : Symbol(IsEqual, Decl(distributedTypeParameters.ts, 111, 56)) {[K in Key]: Type[Key]}, ->K : Symbol(K, Decl(distributedTypeParameters.ts, 71, 7)) ->Key : Symbol(Key, Decl(distributedTypeParameters.ts, 66, 41)) ->Type : Symbol(Type, Decl(distributedTypeParameters.ts, 66, 21)) ->Key : Symbol(Key, Decl(distributedTypeParameters.ts, 66, 41)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 105, 7)) +>Key : Symbol(Key, Decl(distributedTypeParameters.ts, 100, 41)) +>Type : Symbol(Type, Decl(distributedTypeParameters.ts, 100, 21)) +>Key : Symbol(Key, Decl(distributedTypeParameters.ts, 100, 41)) {readonly [K in Key]: Type[Key]} ->K : Symbol(K, Decl(distributedTypeParameters.ts, 72, 16)) ->Key : Symbol(Key, Decl(distributedTypeParameters.ts, 66, 41)) ->Type : Symbol(Type, Decl(distributedTypeParameters.ts, 66, 21)) ->Key : Symbol(Key, Decl(distributedTypeParameters.ts, 66, 41)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 106, 16)) +>Key : Symbol(Key, Decl(distributedTypeParameters.ts, 100, 41)) +>Type : Symbol(Type, Decl(distributedTypeParameters.ts, 100, 21)) +>Key : Symbol(Key, Decl(distributedTypeParameters.ts, 100, 41)) > : never // Should never happen : never; // Should never happen type IsAny = 0 extends 1 & NoInfer ? true : false; ->IsAny : Symbol(IsAny, Decl(distributedTypeParameters.ts, 75, 11)) ->T : Symbol(T, Decl(distributedTypeParameters.ts, 77, 11)) +>IsAny : Symbol(IsAny, Decl(distributedTypeParameters.ts, 109, 11)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 111, 11)) >NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(distributedTypeParameters.ts, 77, 11)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 111, 11)) type IsEqual = ->IsEqual : Symbol(IsEqual, Decl(distributedTypeParameters.ts, 77, 56)) ->A : Symbol(A, Decl(distributedTypeParameters.ts, 79, 13)) ->B : Symbol(B, Decl(distributedTypeParameters.ts, 79, 15)) +>IsEqual : Symbol(IsEqual, Decl(distributedTypeParameters.ts, 111, 56)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 113, 13)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 113, 15)) [A] extends [B] ->A : Symbol(A, Decl(distributedTypeParameters.ts, 79, 13)) ->B : Symbol(B, Decl(distributedTypeParameters.ts, 79, 15)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 113, 13)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 113, 15)) ? [B] extends [A] ->B : Symbol(B, Decl(distributedTypeParameters.ts, 79, 15)) ->A : Symbol(A, Decl(distributedTypeParameters.ts, 79, 13)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 113, 15)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 113, 13)) ? _IsEqual ->_IsEqual : Symbol(_IsEqual, Decl(distributedTypeParameters.ts, 84, 10)) ->A : Symbol(A, Decl(distributedTypeParameters.ts, 79, 13)) ->B : Symbol(B, Decl(distributedTypeParameters.ts, 79, 15)) +>_IsEqual : Symbol(_IsEqual, Decl(distributedTypeParameters.ts, 118, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 113, 13)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 113, 15)) : false : false; type _IsEqual = ->_IsEqual : Symbol(_IsEqual, Decl(distributedTypeParameters.ts, 84, 10)) ->A : Symbol(A, Decl(distributedTypeParameters.ts, 86, 14)) ->B : Symbol(B, Decl(distributedTypeParameters.ts, 86, 16)) +>_IsEqual : Symbol(_IsEqual, Decl(distributedTypeParameters.ts, 118, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 120, 14)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 120, 16)) (() => G extends A & G | G ? 1 : 2) extends ->G : Symbol(G, Decl(distributedTypeParameters.ts, 87, 3)) ->G : Symbol(G, Decl(distributedTypeParameters.ts, 87, 3)) ->A : Symbol(A, Decl(distributedTypeParameters.ts, 86, 14)) ->G : Symbol(G, Decl(distributedTypeParameters.ts, 87, 3)) ->G : Symbol(G, Decl(distributedTypeParameters.ts, 87, 3)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 121, 3)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 121, 3)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 120, 14)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 121, 3)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 121, 3)) (() => G extends B & G | G ? 1 : 2) ->G : Symbol(G, Decl(distributedTypeParameters.ts, 88, 3)) ->G : Symbol(G, Decl(distributedTypeParameters.ts, 88, 3)) ->B : Symbol(B, Decl(distributedTypeParameters.ts, 86, 16)) ->G : Symbol(G, Decl(distributedTypeParameters.ts, 88, 3)) ->G : Symbol(G, Decl(distributedTypeParameters.ts, 88, 3)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 122, 3)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 122, 3)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 120, 16)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 122, 3)) +>G : Symbol(G, Decl(distributedTypeParameters.ts, 122, 3)) ? true : false; type T10 = IsReadonlyKeyOf<{ a: string }, 'a'>; // false ->T10 : Symbol(T10, Decl(distributedTypeParameters.ts, 90, 10)) ->IsReadonlyKeyOf : Symbol(IsReadonlyKeyOf, Decl(distributedTypeParameters.ts, 62, 10)) ->a : Symbol(a, Decl(distributedTypeParameters.ts, 92, 28)) +>T10 : Symbol(T10, Decl(distributedTypeParameters.ts, 124, 10)) +>IsReadonlyKeyOf : Symbol(IsReadonlyKeyOf, Decl(distributedTypeParameters.ts, 96, 12)) +>a : Symbol(a, Decl(distributedTypeParameters.ts, 126, 28)) type T11 = IsReadonlyKeyOf<{ readonly b: string }, 'b'>; // true ->T11 : Symbol(T11, Decl(distributedTypeParameters.ts, 92, 47)) ->IsReadonlyKeyOf : Symbol(IsReadonlyKeyOf, Decl(distributedTypeParameters.ts, 62, 10)) ->b : Symbol(b, Decl(distributedTypeParameters.ts, 93, 28)) +>T11 : Symbol(T11, Decl(distributedTypeParameters.ts, 126, 47)) +>IsReadonlyKeyOf : Symbol(IsReadonlyKeyOf, Decl(distributedTypeParameters.ts, 96, 12)) +>b : Symbol(b, Decl(distributedTypeParameters.ts, 127, 28)) + +// Repro from triggerdotdev/trigger.dev + +type Exact = +>Exact : Symbol(Exact, Decl(distributedTypeParameters.ts, 127, 56)) +>P : Symbol(P, Decl(distributedTypeParameters.ts, 131, 11)) +>I : Symbol(I, Decl(distributedTypeParameters.ts, 131, 13)) +>P : Symbol(P, Decl(distributedTypeParameters.ts, 131, 11)) + + P extends unknown ? +>P : Symbol(P, Decl(distributedTypeParameters.ts, 131, 11)) + + { [K in keyof P]: Exact } : // Error +>K : Symbol(K, Decl(distributedTypeParameters.ts, 133, 7)) +>P : Symbol(P, Decl(distributedTypeParameters.ts, 131, 11)) +>Exact : Symbol(Exact, Decl(distributedTypeParameters.ts, 127, 56)) +>P : Symbol(P, Decl(distributedTypeParameters.ts, 131, 11)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 133, 7)) +>I : Symbol(I, Decl(distributedTypeParameters.ts, 131, 13)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 133, 7)) + + never; + +type X7 = Exact<{ a: 0 } | { b: 1 }, { a: 0 }>; +>X7 : Symbol(X7, Decl(distributedTypeParameters.ts, 134, 10)) +>Exact : Symbol(Exact, Decl(distributedTypeParameters.ts, 127, 56)) +>a : Symbol(a, Decl(distributedTypeParameters.ts, 136, 17)) +>b : Symbol(b, Decl(distributedTypeParameters.ts, 136, 28)) +>a : Symbol(a, Decl(distributedTypeParameters.ts, 136, 38)) + +// Homomorphic mapped types instantiated for a distributed type parameter keep its distributed form + +type Mutable = { -readonly [K in keyof T]: T[K] }; +>Mutable : Symbol(Mutable, Decl(distributedTypeParameters.ts, 136, 47)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 140, 13)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 140, 31)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 140, 13)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 140, 13)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 140, 31)) + +type C1 = T extends unknown ? Show, U> : never; // Error +>C1 : Symbol(C1, Decl(distributedTypeParameters.ts, 140, 53)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 142, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 142, 10)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 142, 8)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 142, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>Mutable : Symbol(Mutable, Decl(distributedTypeParameters.ts, 136, 47)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 142, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 142, 10)) + +type C2 = T extends unknown ? Show, U> : never; // Error +>C2 : Symbol(C2, Decl(distributedTypeParameters.ts, 142, 74)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 143, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 143, 10)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 143, 8)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 143, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 143, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 143, 10)) + +type C3 = T extends unknown ? Show, Mutable> : never; // Error +>C3 : Symbol(C3, Decl(distributedTypeParameters.ts, 143, 74)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 144, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 144, 10)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 144, 8)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 144, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>Mutable : Symbol(Mutable, Decl(distributedTypeParameters.ts, 136, 47)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 144, 8)) +>Mutable : Symbol(Mutable, Decl(distributedTypeParameters.ts, 136, 47)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 144, 10)) + +type C4 = T extends unknown ? Show<{ [K in keyof T]: T[K] }, U> : never; // Error +>C4 : Symbol(C4, Decl(distributedTypeParameters.ts, 144, 83)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 145, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 145, 10)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 145, 8)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 145, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 145, 54)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 145, 8)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 145, 8)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 145, 54)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 145, 10)) + +type M4 = { [K in keyof T]: Show, U> }; // Error +>M4 : Symbol(M4, Decl(distributedTypeParameters.ts, 145, 88)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 146, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 146, 10)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 146, 8)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 146, 29)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 146, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>Mutable : Symbol(Mutable, Decl(distributedTypeParameters.ts, 136, 47)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 146, 8)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 146, 10)) + +// Normalization doesn't depend on whether the template was resolved before + +declare function inferFromMappedGetter(u: { [K in keyof U]: () => U }): () => U; +>inferFromMappedGetter : Symbol(inferFromMappedGetter, Decl(distributedTypeParameters.ts, 146, 66)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 150, 39)) +>u : Symbol(u, Decl(distributedTypeParameters.ts, 150, 42)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 150, 48)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 150, 39)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 150, 39)) +>U : Symbol(U, Decl(distributedTypeParameters.ts, 150, 39)) + +function f1(getter: () => T) { +>f1 : Symbol(f1, Decl(distributedTypeParameters.ts, 150, 83)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 152, 12)) +>getter : Symbol(getter, Decl(distributedTypeParameters.ts, 152, 15)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 152, 12)) + + let r = inferFromMappedGetter(get()); +>r : Symbol(r, Decl(distributedTypeParameters.ts, 153, 5)) +>inferFromMappedGetter : Symbol(inferFromMappedGetter, Decl(distributedTypeParameters.ts, 146, 66)) +>get : Symbol(get, Decl(distributedTypeParameters.ts, 154, 13)) + + r = getter; +>r : Symbol(r, Decl(distributedTypeParameters.ts, 153, 5)) +>getter : Symbol(getter, Decl(distributedTypeParameters.ts, 152, 15)) + + function get(): { [K in keyof T]: () => T } { return null!; } +>get : Symbol(get, Decl(distributedTypeParameters.ts, 154, 13)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 155, 21)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 152, 12)) +>T : Symbol(T, Decl(distributedTypeParameters.ts, 152, 12)) +} + +type M5 = { [K in keyof A]: { [J in keyof B]: Show } }; +>M5 : Symbol(M5, Decl(distributedTypeParameters.ts, 156, 1)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 158, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 158, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 158, 8)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 158, 29)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 158, 8)) +>J : Symbol(J, Decl(distributedTypeParameters.ts, 158, 47)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 158, 10)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 158, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 158, 10)) + +type M6 = { [K in keyof B]: { [J in keyof A]: Show } }; +>M6 : Symbol(M6, Decl(distributedTypeParameters.ts, 158, 77)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 159, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 159, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 159, 8)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 159, 29)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 159, 10)) +>J : Symbol(J, Decl(distributedTypeParameters.ts, 159, 47)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 159, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 159, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 159, 10)) + +type M7 = { [K in keyof A]: Show }; +>M7 : Symbol(M7, Decl(distributedTypeParameters.ts, 159, 77)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 160, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 160, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 160, 8)) +>C : Symbol(C, Decl(distributedTypeParameters.ts, 160, 23)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 160, 10)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 160, 42)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 160, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 160, 8)) +>C : Symbol(C, Decl(distributedTypeParameters.ts, 160, 23)) + +type M8 = { [K in keyof A]: { [J in keyof B]: [Show, Show] } }; +>M8 : Symbol(M8, Decl(distributedTypeParameters.ts, 160, 70)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 161, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 161, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 161, 8)) +>C : Symbol(C, Decl(distributedTypeParameters.ts, 161, 23)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 161, 10)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 161, 42)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 161, 8)) +>J : Symbol(J, Decl(distributedTypeParameters.ts, 161, 60)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 161, 10)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 161, 8)) +>C : Symbol(C, Decl(distributedTypeParameters.ts, 161, 23)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 161, 10)) +>C : Symbol(C, Decl(distributedTypeParameters.ts, 161, 23)) + +type M9 = { [K in keyof A as Show extends never ? never : K]: 0 }; +>M9 : Symbol(M9, Decl(distributedTypeParameters.ts, 161, 104)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 162, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 162, 10)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 162, 8)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 162, 29)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 162, 8)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 162, 8)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 162, 10)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 162, 29)) + +type M10 = { [K in keyof [A]]: Show }; +>M10 : Symbol(M10, Decl(distributedTypeParameters.ts, 162, 88)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 163, 9)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 163, 11)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 163, 9)) +>K : Symbol(K, Decl(distributedTypeParameters.ts, 163, 30)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 163, 9)) +>Show : Symbol(Show, Decl(distributedTypeParameters.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParameters.ts, 163, 9)) +>B : Symbol(B, Decl(distributedTypeParameters.ts, 163, 11)) diff --git a/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.types b/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.types index 37fe5d3abaed0..7f39cd5a00fc5 100644 --- a/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.types +++ b/tsc/testdata/baselines/reference/compiler/distributedTypeParameters.types @@ -91,6 +91,88 @@ type T5 = Show : never; +type M1 = { +>M1 : M1 + + [K in keyof A]: Show; // Error +}; + +type M2 = { +>M2 : M2 + + [K in keyof A as K]: Show; // Error +}; + +type M3 = { +>M3 : M3 + + [K in keyof A & string]: Show; +}; + +type X5 = M1<{ a: 0 } | { b: 1 }, { a: 0 }>; +>X5 : X5 +>a : 0 +>b : 1 +>a : 0 + +type X6 = M2<{ a: 0 } | { b: 1 }, { a: 0 }>; +>X6 : X6 +>a : 0 +>b : 1 +>a : 0 + +type ShowResult = U extends T ? true : false; +>ShowResult : ShowResult +>true : true +>false : false + +declare function conditionalIndexedAccess(y: U): +>conditionalIndexedAccess : (y: U) => T extends unknown ? ShowResult : never +>y : U + + T extends unknown ? ShowResult : never; // Error + +const conditionalIndexedAccessResult = conditionalIndexedAccess< +>conditionalIndexedAccessResult : boolean +>conditionalIndexedAccess< { a: 1 } | { b: 2 }, { a: 1 }>({ a: 1 }) : boolean +>conditionalIndexedAccess : (y: U) => T extends unknown ? ShowResult : never + + { a: 1 } | { b: 2 }, +>a : 1 +>b : 2 + + { a: 1 } +>a : 1 + +>({ a: 1 }); +>{ a: 1 } : { a: 1; } +>a : 1 +>1 : 1 + +declare function mappedIndexedAccess(y: U): { +>mappedIndexedAccess : (y: U) => { [P in keyof T]: ShowResult; } +>y : U + + [P in keyof T]: ShowResult; // Error +}; + +const mappedIndexedAccessResult = mappedIndexedAccess< +>mappedIndexedAccessResult : { a: true; } | { b: false; } +>mappedIndexedAccess< { a: 1 } | { b: 2 }, { a: 1 }>({ a: 1 }) : { a: true; } | { b: false; } +>mappedIndexedAccess : (y: U) => { [P in keyof T]: ShowResult; } + + { a: 1 } | { b: 2 }, +>a : 1 +>b : 2 + + { a: 1 } +>a : 1 + +>({ a: 1 }); +>{ a: 1 } : { a: 1; } +>a : 1 +>1 : 1 + // Ensure mapped type modifiers are computed correctly, example from type-fest type IsReadonlyKeyOf = @@ -144,3 +226,83 @@ type T11 = IsReadonlyKeyOf<{ readonly b: string }, 'b'>; // true >T11 : true >b : string +// Repro from triggerdotdev/trigger.dev + +type Exact = +>Exact : Exact + + P extends unknown ? + { [K in keyof P]: Exact } : // Error + never; + +type X7 = Exact<{ a: 0 } | { b: 1 }, { a: 0 }>; +>X7 : X7 +>a : 0 +>b : 1 +>a : 0 + +// Homomorphic mapped types instantiated for a distributed type parameter keep its distributed form + +type Mutable = { -readonly [K in keyof T]: T[K] }; +>Mutable : Mutable + +type C1 = T extends unknown ? Show, U> : never; // Error +>C1 : C1 + +type C2 = T extends unknown ? Show, U> : never; // Error +>C2 : C2 + +type C3 = T extends unknown ? Show, Mutable> : never; // Error +>C3 : C3 + +type C4 = T extends unknown ? Show<{ [K in keyof T]: T[K] }, U> : never; // Error +>C4 : C4 + +type M4 = { [K in keyof T]: Show, U> }; // Error +>M4 : M4 + +// Normalization doesn't depend on whether the template was resolved before + +declare function inferFromMappedGetter(u: { [K in keyof U]: () => U }): () => U; +>inferFromMappedGetter : (u: { [K in keyof U]: () => U; }) => () => U +>u : { [K in keyof U]: () => U; } + +function f1(getter: () => T) { +>f1 : (getter: () => T) => void +>getter : () => T + + let r = inferFromMappedGetter(get()); +>r : () => T +>inferFromMappedGetter(get()) : () => T +>inferFromMappedGetter : (u: { [K in keyof U]: () => U; }) => () => U +>get() : { [K in keyof T]: () => T; } +>get : () => { [K in keyof T]: () => T; } + + r = getter; +>r = getter : () => T +>r : () => T +>getter : () => T + + function get(): { [K in keyof T]: () => T } { return null!; } +>get : () => { [K in keyof T]: () => T; } +>null! : never +} + +type M5 = { [K in keyof A]: { [J in keyof B]: Show } }; +>M5 : M5 + +type M6 = { [K in keyof B]: { [J in keyof A]: Show } }; +>M6 : M6 + +type M7 = { [K in keyof A]: Show }; +>M7 : M7 + +type M8 = { [K in keyof A]: { [J in keyof B]: [Show, Show] } }; +>M8 : M8 + +type M9 = { [K in keyof A as Show extends never ? never : K]: 0 }; +>M9 : M9 + +type M10 = { [K in keyof [A]]: Show }; +>M10 : M10 + diff --git a/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.errors.txt b/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.errors.txt new file mode 100644 index 0000000000000..78007d48c4e7a --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.errors.txt @@ -0,0 +1,49 @@ +distributedTypeParametersParenthesized.ts(3,65): error TS2344: Type 'U' does not satisfy the constraint 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParametersParenthesized.ts(4,67): error TS2344: Type 'U' does not satisfy the constraint 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParametersParenthesized.ts(5,69): error TS2344: Type 'U' does not satisfy the constraint 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParametersParenthesized.ts(7,58): error TS2344: Type 'U' does not satisfy the constraint 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParametersParenthesized.ts(8,60): error TS2344: Type 'U' does not satisfy the constraint 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParametersParenthesized.ts(9,60): error TS2344: Type 'U' does not satisfy the constraint 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. +distributedTypeParametersParenthesized.ts(10,64): error TS2344: Type 'U' does not satisfy the constraint 'T'. + 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + + +==== distributedTypeParametersParenthesized.ts (7 errors) ==== + type Show = B extends A ? true : false; + + type Conditional1 = T extends unknown ? Show : never; + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + type Conditional2 = (T) extends unknown ? Show : never; + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + type Conditional3 = ((T)) extends unknown ? Show : never; + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + + type Mapped1 = { [K in keyof T]: Show }; + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + type Mapped2 = { [K in keyof (T)]: Show }; + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + type Mapped3 = { [K in (keyof T)]: Show }; + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + type Mapped4 = { [K in ((keyof (T)))]: Show }; + ~ +!!! error TS2344: Type 'U' does not satisfy the constraint 'T'. +!!! error TS2344: 'U' is only assignable to the non-distributed 'T', but 'T' has been distributed here. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.symbols b/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.symbols new file mode 100644 index 0000000000000..7cd48bfa628eb --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.symbols @@ -0,0 +1,85 @@ +//// [tests/cases/compiler/distributedTypeParametersParenthesized.ts] //// + +=== distributedTypeParametersParenthesized.ts === +type Show = B extends A ? true : false; +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>A : Symbol(A, Decl(distributedTypeParametersParenthesized.ts, 0, 10)) +>B : Symbol(B, Decl(distributedTypeParametersParenthesized.ts, 0, 12)) +>A : Symbol(A, Decl(distributedTypeParametersParenthesized.ts, 0, 10)) +>B : Symbol(B, Decl(distributedTypeParametersParenthesized.ts, 0, 12)) +>A : Symbol(A, Decl(distributedTypeParametersParenthesized.ts, 0, 10)) + +type Conditional1 = T extends unknown ? Show : never; +>Conditional1 : Symbol(Conditional1, Decl(distributedTypeParametersParenthesized.ts, 0, 55)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 2, 18)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 2, 20)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 2, 18)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 2, 18)) +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 2, 18)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 2, 20)) + +type Conditional2 = (T) extends unknown ? Show : never; +>Conditional2 : Symbol(Conditional2, Decl(distributedTypeParametersParenthesized.ts, 2, 75)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 3, 18)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 3, 20)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 3, 18)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 3, 18)) +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 3, 18)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 3, 20)) + +type Conditional3 = ((T)) extends unknown ? Show : never; +>Conditional3 : Symbol(Conditional3, Decl(distributedTypeParametersParenthesized.ts, 3, 77)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 4, 18)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 4, 20)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 4, 18)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 4, 18)) +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 4, 18)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 4, 20)) + +type Mapped1 = { [K in keyof T]: Show }; +>Mapped1 : Symbol(Mapped1, Decl(distributedTypeParametersParenthesized.ts, 4, 79)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 6, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 6, 15)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 6, 13)) +>K : Symbol(K, Decl(distributedTypeParametersParenthesized.ts, 6, 34)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 6, 13)) +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 6, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 6, 15)) + +type Mapped2 = { [K in keyof (T)]: Show }; +>Mapped2 : Symbol(Mapped2, Decl(distributedTypeParametersParenthesized.ts, 6, 62)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 7, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 7, 15)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 7, 13)) +>K : Symbol(K, Decl(distributedTypeParametersParenthesized.ts, 7, 34)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 7, 13)) +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 7, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 7, 15)) + +type Mapped3 = { [K in (keyof T)]: Show }; +>Mapped3 : Symbol(Mapped3, Decl(distributedTypeParametersParenthesized.ts, 7, 64)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 8, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 8, 15)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 8, 13)) +>K : Symbol(K, Decl(distributedTypeParametersParenthesized.ts, 8, 34)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 8, 13)) +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 8, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 8, 15)) + +type Mapped4 = { [K in ((keyof (T)))]: Show }; +>Mapped4 : Symbol(Mapped4, Decl(distributedTypeParametersParenthesized.ts, 8, 64)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 9, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 9, 15)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 9, 13)) +>K : Symbol(K, Decl(distributedTypeParametersParenthesized.ts, 9, 34)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 9, 13)) +>Show : Symbol(Show, Decl(distributedTypeParametersParenthesized.ts, 0, 0)) +>T : Symbol(T, Decl(distributedTypeParametersParenthesized.ts, 9, 13)) +>U : Symbol(U, Decl(distributedTypeParametersParenthesized.ts, 9, 15)) + diff --git a/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.types b/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.types new file mode 100644 index 0000000000000..142429a1406c1 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/distributedTypeParametersParenthesized.types @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/distributedTypeParametersParenthesized.ts] //// + +=== distributedTypeParametersParenthesized.ts === +type Show = B extends A ? true : false; +>Show : Show +>true : true +>false : false + +type Conditional1 = T extends unknown ? Show : never; +>Conditional1 : Conditional1 + +type Conditional2 = (T) extends unknown ? Show : never; +>Conditional2 : Conditional2 + +type Conditional3 = ((T)) extends unknown ? Show : never; +>Conditional3 : Conditional3 + +type Mapped1 = { [K in keyof T]: Show }; +>Mapped1 : Mapped1 + +type Mapped2 = { [K in keyof (T)]: Show }; +>Mapped2 : Mapped2 + +type Mapped3 = { [K in (keyof T)]: Show }; +>Mapped3 : Mapped3 + +type Mapped4 = { [K in ((keyof (T)))]: Show }; +>Mapped4 : Mapped4 + diff --git a/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.js b/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.js new file mode 100644 index 0000000000000..d0b611d774666 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.js @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/reverseMappedTypeNestedInference.ts] //// + +//// [reverseMappedTypeNestedInference.ts] +declare const sv: (input: unknown) => string | undefined; + +declare function d3(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: (i: unknown) => T[K][J][L] } } }): T; +export const r3 = d3({ a: { b: { c: sv } } }); + +declare function d4(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: { [M in keyof T[K][J][L]]: (i: unknown) => T[K][J][L][M] } } } }): T; +export const r4 = d4({ a: { b: { c: { d: sv } } } }); + +type Deep2 = { [K in keyof T]: { [J in keyof T[K]]: Deep2 | ((i: unknown) => T[K][J]) } }; +declare function dd(input: Deep2): T; +export const rd = dd({ a: { b: { c: { d: sv } } } }); + +declare function dk(input: { [K in keyof T]: { [J in keyof T[K]]: (i: unknown) => T[K][J] } }, k: U): T[U]; +export const rk = dk({ a: { b: sv } }, "a"); + +declare function revTuple(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +export const rt = revTuple([{ a: () => 1 }, { b: () => "s" }] as const); + +declare function revTupleUnconstrained(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +export const rtu = revTupleUnconstrained([{ a: () => 1 }, { b: () => "s" }] as const); + + +//// [reverseMappedTypeNestedInference.js] +export const r3 = d3({ a: { b: { c: sv } } }); +export const r4 = d4({ a: { b: { c: { d: sv } } } }); +export const rd = dd({ a: { b: { c: { d: sv } } } }); +export const rk = dk({ a: { b: sv } }, "a"); +export const rt = revTuple([{ a: () => 1 }, { b: () => "s" }]); +export const rtu = revTupleUnconstrained([{ a: () => 1 }, { b: () => "s" }]); + + +//// [reverseMappedTypeNestedInference.d.ts] +export declare const r3: { + a: { + b: { + c: string | undefined; + }; + }; +}; +export declare const r4: { + a: { + b: { + c: { + d: string | undefined; + }; + }; + }; +}; +export declare const rd: { + a: { + b: { + c: { + d: string | undefined; + }; + }; + }; +}; +export declare const rk: { + b: string | undefined; +}; +export declare const rt: [{ + readonly a: number; +}, { + readonly b: string; +}]; +export declare const rtu: readonly [{ + readonly a: number; +}, { + readonly b: string; +}]; diff --git a/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.symbols b/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.symbols new file mode 100644 index 0000000000000..fb03465307fdd --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.symbols @@ -0,0 +1,173 @@ +//// [tests/cases/compiler/reverseMappedTypeNestedInference.ts] //// + +=== reverseMappedTypeNestedInference.ts === +declare const sv: (input: unknown) => string | undefined; +>sv : Symbol(sv, Decl(reverseMappedTypeNestedInference.ts, 0, 13)) +>input : Symbol(input, Decl(reverseMappedTypeNestedInference.ts, 0, 19)) + +declare function d3(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: (i: unknown) => T[K][J][L] } } }): T; +>d3 : Symbol(d3, Decl(reverseMappedTypeNestedInference.ts, 0, 57)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 2, 20)) +>input : Symbol(input, Decl(reverseMappedTypeNestedInference.ts, 2, 23)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 2, 33)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 2, 20)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 2, 51)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 2, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 2, 33)) +>L : Symbol(L, Decl(reverseMappedTypeNestedInference.ts, 2, 72)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 2, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 2, 33)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 2, 51)) +>i : Symbol(i, Decl(reverseMappedTypeNestedInference.ts, 2, 94)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 2, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 2, 33)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 2, 51)) +>L : Symbol(L, Decl(reverseMappedTypeNestedInference.ts, 2, 72)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 2, 20)) + +export const r3 = d3({ a: { b: { c: sv } } }); +>r3 : Symbol(r3, Decl(reverseMappedTypeNestedInference.ts, 3, 12)) +>d3 : Symbol(d3, Decl(reverseMappedTypeNestedInference.ts, 0, 57)) +>a : Symbol(a, Decl(reverseMappedTypeNestedInference.ts, 3, 22)) +>b : Symbol(b, Decl(reverseMappedTypeNestedInference.ts, 3, 27)) +>c : Symbol(c, Decl(reverseMappedTypeNestedInference.ts, 3, 32)) +>sv : Symbol(sv, Decl(reverseMappedTypeNestedInference.ts, 0, 13)) + +declare function d4(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: { [M in keyof T[K][J][L]]: (i: unknown) => T[K][J][L][M] } } } }): T; +>d4 : Symbol(d4, Decl(reverseMappedTypeNestedInference.ts, 3, 46)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 5, 20)) +>input : Symbol(input, Decl(reverseMappedTypeNestedInference.ts, 5, 23)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 5, 33)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 5, 20)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 5, 51)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 5, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 5, 33)) +>L : Symbol(L, Decl(reverseMappedTypeNestedInference.ts, 5, 72)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 5, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 5, 33)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 5, 51)) +>M : Symbol(M, Decl(reverseMappedTypeNestedInference.ts, 5, 96)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 5, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 5, 33)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 5, 51)) +>L : Symbol(L, Decl(reverseMappedTypeNestedInference.ts, 5, 72)) +>i : Symbol(i, Decl(reverseMappedTypeNestedInference.ts, 5, 121)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 5, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 5, 33)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 5, 51)) +>L : Symbol(L, Decl(reverseMappedTypeNestedInference.ts, 5, 72)) +>M : Symbol(M, Decl(reverseMappedTypeNestedInference.ts, 5, 96)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 5, 20)) + +export const r4 = d4({ a: { b: { c: { d: sv } } } }); +>r4 : Symbol(r4, Decl(reverseMappedTypeNestedInference.ts, 6, 12)) +>d4 : Symbol(d4, Decl(reverseMappedTypeNestedInference.ts, 3, 46)) +>a : Symbol(a, Decl(reverseMappedTypeNestedInference.ts, 6, 22)) +>b : Symbol(b, Decl(reverseMappedTypeNestedInference.ts, 6, 27)) +>c : Symbol(c, Decl(reverseMappedTypeNestedInference.ts, 6, 32)) +>d : Symbol(d, Decl(reverseMappedTypeNestedInference.ts, 6, 37)) +>sv : Symbol(sv, Decl(reverseMappedTypeNestedInference.ts, 0, 13)) + +type Deep2 = { [K in keyof T]: { [J in keyof T[K]]: Deep2 | ((i: unknown) => T[K][J]) } }; +>Deep2 : Symbol(Deep2, Decl(reverseMappedTypeNestedInference.ts, 6, 53)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 8, 11)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 8, 19)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 8, 11)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 8, 37)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 8, 11)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 8, 19)) +>Deep2 : Symbol(Deep2, Decl(reverseMappedTypeNestedInference.ts, 6, 53)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 8, 11)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 8, 19)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 8, 37)) +>i : Symbol(i, Decl(reverseMappedTypeNestedInference.ts, 8, 74)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 8, 11)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 8, 19)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 8, 37)) + +declare function dd(input: Deep2): T; +>dd : Symbol(dd, Decl(reverseMappedTypeNestedInference.ts, 8, 102)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 9, 20)) +>input : Symbol(input, Decl(reverseMappedTypeNestedInference.ts, 9, 23)) +>Deep2 : Symbol(Deep2, Decl(reverseMappedTypeNestedInference.ts, 6, 53)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 9, 20)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 9, 20)) + +export const rd = dd({ a: { b: { c: { d: sv } } } }); +>rd : Symbol(rd, Decl(reverseMappedTypeNestedInference.ts, 10, 12)) +>dd : Symbol(dd, Decl(reverseMappedTypeNestedInference.ts, 8, 102)) +>a : Symbol(a, Decl(reverseMappedTypeNestedInference.ts, 10, 22)) +>b : Symbol(b, Decl(reverseMappedTypeNestedInference.ts, 10, 27)) +>c : Symbol(c, Decl(reverseMappedTypeNestedInference.ts, 10, 32)) +>d : Symbol(d, Decl(reverseMappedTypeNestedInference.ts, 10, 37)) +>sv : Symbol(sv, Decl(reverseMappedTypeNestedInference.ts, 0, 13)) + +declare function dk(input: { [K in keyof T]: { [J in keyof T[K]]: (i: unknown) => T[K][J] } }, k: U): T[U]; +>dk : Symbol(dk, Decl(reverseMappedTypeNestedInference.ts, 10, 53)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 12, 20)) +>U : Symbol(U, Decl(reverseMappedTypeNestedInference.ts, 12, 22)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 12, 20)) +>input : Symbol(input, Decl(reverseMappedTypeNestedInference.ts, 12, 42)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 12, 52)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 12, 20)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 12, 70)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 12, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 12, 52)) +>i : Symbol(i, Decl(reverseMappedTypeNestedInference.ts, 12, 89)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 12, 20)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 12, 52)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 12, 70)) +>k : Symbol(k, Decl(reverseMappedTypeNestedInference.ts, 12, 116)) +>U : Symbol(U, Decl(reverseMappedTypeNestedInference.ts, 12, 22)) +>T : Symbol(T, Decl(reverseMappedTypeNestedInference.ts, 12, 20)) +>U : Symbol(U, Decl(reverseMappedTypeNestedInference.ts, 12, 22)) + +export const rk = dk({ a: { b: sv } }, "a"); +>rk : Symbol(rk, Decl(reverseMappedTypeNestedInference.ts, 13, 12)) +>dk : Symbol(dk, Decl(reverseMappedTypeNestedInference.ts, 10, 53)) +>a : Symbol(a, Decl(reverseMappedTypeNestedInference.ts, 13, 22)) +>b : Symbol(b, Decl(reverseMappedTypeNestedInference.ts, 13, 27)) +>sv : Symbol(sv, Decl(reverseMappedTypeNestedInference.ts, 0, 13)) + +declare function revTuple(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +>revTuple : Symbol(revTuple, Decl(reverseMappedTypeNestedInference.ts, 13, 44)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 15, 26)) +>x : Symbol(x, Decl(reverseMappedTypeNestedInference.ts, 15, 47)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 15, 53)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 15, 26)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 15, 71)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 15, 26)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 15, 53)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 15, 26)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 15, 53)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 15, 71)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 15, 26)) + +export const rt = revTuple([{ a: () => 1 }, { b: () => "s" }] as const); +>rt : Symbol(rt, Decl(reverseMappedTypeNestedInference.ts, 16, 12)) +>revTuple : Symbol(revTuple, Decl(reverseMappedTypeNestedInference.ts, 13, 44)) +>a : Symbol(a, Decl(reverseMappedTypeNestedInference.ts, 16, 29)) +>b : Symbol(b, Decl(reverseMappedTypeNestedInference.ts, 16, 45)) +>const : Symbol(const) + +declare function revTupleUnconstrained(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +>revTupleUnconstrained : Symbol(revTupleUnconstrained, Decl(reverseMappedTypeNestedInference.ts, 16, 72)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 18, 39)) +>x : Symbol(x, Decl(reverseMappedTypeNestedInference.ts, 18, 42)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 18, 48)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 18, 39)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 18, 66)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 18, 39)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 18, 48)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 18, 39)) +>K : Symbol(K, Decl(reverseMappedTypeNestedInference.ts, 18, 48)) +>J : Symbol(J, Decl(reverseMappedTypeNestedInference.ts, 18, 66)) +>V : Symbol(V, Decl(reverseMappedTypeNestedInference.ts, 18, 39)) + +export const rtu = revTupleUnconstrained([{ a: () => 1 }, { b: () => "s" }] as const); +>rtu : Symbol(rtu, Decl(reverseMappedTypeNestedInference.ts, 19, 12)) +>revTupleUnconstrained : Symbol(revTupleUnconstrained, Decl(reverseMappedTypeNestedInference.ts, 16, 72)) +>a : Symbol(a, Decl(reverseMappedTypeNestedInference.ts, 19, 43)) +>b : Symbol(b, Decl(reverseMappedTypeNestedInference.ts, 19, 59)) +>const : Symbol(const) + diff --git a/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.types b/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.types new file mode 100644 index 0000000000000..3a7038a429344 --- /dev/null +++ b/tsc/testdata/baselines/reference/compiler/reverseMappedTypeNestedInference.types @@ -0,0 +1,120 @@ +//// [tests/cases/compiler/reverseMappedTypeNestedInference.ts] //// + +=== reverseMappedTypeNestedInference.ts === +declare const sv: (input: unknown) => string | undefined; +>sv : (input: unknown) => string | undefined +>input : unknown + +declare function d3(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: (i: unknown) => T[K][J][L] } } }): T; +>d3 : (input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: (i: unknown) => T[K][J][L]; }; }; }) => T +>input : { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: (i: unknown) => T[K][J][L]; }; }; } +>i : unknown + +export const r3 = d3({ a: { b: { c: sv } } }); +>r3 : { a: { b: { c: string | undefined; }; }; } +>d3({ a: { b: { c: sv } } }) : { a: { b: { c: string | undefined; }; }; } +>d3 : (input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: (i: unknown) => T[K][J][L]; }; }; }) => T +>{ a: { b: { c: sv } } } : { a: { b: { c: (input: unknown) => string | undefined; }; }; } +>a : { b: { c: (input: unknown) => string | undefined; }; } +>{ b: { c: sv } } : { b: { c: (input: unknown) => string | undefined; }; } +>b : { c: (input: unknown) => string | undefined; } +>{ c: sv } : { c: (input: unknown) => string | undefined; } +>c : (input: unknown) => string | undefined +>sv : (input: unknown) => string | undefined + +declare function d4(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: { [M in keyof T[K][J][L]]: (i: unknown) => T[K][J][L][M] } } } }): T; +>d4 : (input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: { [M in keyof T[K][J][L]]: (i: unknown) => T[K][J][L][M]; }; }; }; }) => T +>input : { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: { [M in keyof T[K][J][L]]: (i: unknown) => T[K][J][L][M]; }; }; }; } +>i : unknown + +export const r4 = d4({ a: { b: { c: { d: sv } } } }); +>r4 : { a: { b: { c: { d: string | undefined; }; }; }; } +>d4({ a: { b: { c: { d: sv } } } }) : { a: { b: { c: { d: string | undefined; }; }; }; } +>d4 : (input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: { [M in keyof T[K][J][L]]: (i: unknown) => T[K][J][L][M]; }; }; }; }) => T +>{ a: { b: { c: { d: sv } } } } : { a: { b: { c: { d: (input: unknown) => string | undefined; }; }; }; } +>a : { b: { c: { d: (input: unknown) => string | undefined; }; }; } +>{ b: { c: { d: sv } } } : { b: { c: { d: (input: unknown) => string | undefined; }; }; } +>b : { c: { d: (input: unknown) => string | undefined; }; } +>{ c: { d: sv } } : { c: { d: (input: unknown) => string | undefined; }; } +>c : { d: (input: unknown) => string | undefined; } +>{ d: sv } : { d: (input: unknown) => string | undefined; } +>d : (input: unknown) => string | undefined +>sv : (input: unknown) => string | undefined + +type Deep2 = { [K in keyof T]: { [J in keyof T[K]]: Deep2 | ((i: unknown) => T[K][J]) } }; +>Deep2 : Deep2 +>i : unknown + +declare function dd(input: Deep2): T; +>dd : (input: Deep2) => T +>input : Deep2 + +export const rd = dd({ a: { b: { c: { d: sv } } } }); +>rd : { a: { b: { c: { d: any; }; }; }; } +>dd({ a: { b: { c: { d: sv } } } }) : { a: { b: { c: { d: any; }; }; }; } +>dd : (input: Deep2) => T +>{ a: { b: { c: { d: sv } } } } : { a: { b: { c: { d: (input: unknown) => string | undefined; }; }; }; } +>a : { b: { c: { d: (input: unknown) => string | undefined; }; }; } +>{ b: { c: { d: sv } } } : { b: { c: { d: (input: unknown) => string | undefined; }; }; } +>b : { c: { d: (input: unknown) => string | undefined; }; } +>{ c: { d: sv } } : { c: { d: (input: unknown) => string | undefined; }; } +>c : { d: (input: unknown) => string | undefined; } +>{ d: sv } : { d: (input: unknown) => string | undefined; } +>d : (input: unknown) => string | undefined +>sv : (input: unknown) => string | undefined + +declare function dk(input: { [K in keyof T]: { [J in keyof T[K]]: (i: unknown) => T[K][J] } }, k: U): T[U]; +>dk : (input: { [K in keyof T]: { [J in keyof T[K]]: (i: unknown) => T[K][J]; }; }, k: U) => T[U] +>input : { [K in keyof T]: { [J in keyof T[K]]: (i: unknown) => T[K][J]; }; } +>i : unknown +>k : U + +export const rk = dk({ a: { b: sv } }, "a"); +>rk : { b: string | undefined; } +>dk({ a: { b: sv } }, "a") : { b: string | undefined; } +>dk : (input: { [K in keyof T]: { [J in keyof T[K]]: (i: unknown) => T[K][J]; }; }, k: U) => T[U] +>{ a: { b: sv } } : { a: { b: (input: unknown) => string | undefined; }; } +>a : { b: (input: unknown) => string | undefined; } +>{ b: sv } : { b: (input: unknown) => string | undefined; } +>b : (input: unknown) => string | undefined +>sv : (input: unknown) => string | undefined +>"a" : "a" + +declare function revTuple(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +>revTuple : (x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J]; }; }) => V +>x : { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J]; }; } + +export const rt = revTuple([{ a: () => 1 }, { b: () => "s" }] as const); +>rt : [{ readonly a: number; }, { readonly b: string; }] +>revTuple([{ a: () => 1 }, { b: () => "s" }] as const) : [{ readonly a: number; }, { readonly b: string; }] +>revTuple : (x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J]; }; }) => V +>[{ a: () => 1 }, { b: () => "s" }] as const : [{ readonly a: () => number; }, { readonly b: () => string; }] +>[{ a: () => 1 }, { b: () => "s" }] : [{ readonly a: () => number; }, { readonly b: () => string; }] +>{ a: () => 1 } : { readonly a: () => number; } +>a : () => number +>() => 1 : () => number +>1 : 1 +>{ b: () => "s" } : { readonly b: () => string; } +>b : () => string +>() => "s" : () => string +>"s" : "s" + +declare function revTupleUnconstrained(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +>revTupleUnconstrained : (x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J]; }; }) => V +>x : { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J]; }; } + +export const rtu = revTupleUnconstrained([{ a: () => 1 }, { b: () => "s" }] as const); +>rtu : readonly [{ readonly a: number; }, { readonly b: string; }] +>revTupleUnconstrained([{ a: () => 1 }, { b: () => "s" }] as const) : readonly [{ readonly a: number; }, { readonly b: string; }] +>revTupleUnconstrained : (x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J]; }; }) => V +>[{ a: () => 1 }, { b: () => "s" }] as const : readonly [{ readonly a: () => number; }, { readonly b: () => string; }] +>[{ a: () => 1 }, { b: () => "s" }] : readonly [{ readonly a: () => number; }, { readonly b: () => string; }] +>{ a: () => 1 } : { readonly a: () => number; } +>a : () => number +>() => 1 : () => number +>1 : 1 +>{ b: () => "s" } : { readonly b: () => string; } +>b : () => string +>() => "s" : () => string +>"s" : "s" + diff --git a/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.js b/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.js index c805535fd0d3c..f6e8ef26ff557 100644 --- a/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.js +++ b/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.js @@ -179,6 +179,83 @@ const myAny: any = {}; const o1 = getProps(myAny, ['foo', 'bar']); const o2: { foo: any; bar: any } = getProps(myAny, ['foo', 'bar']); + +// Inference between homomorphic mapped types should infer the original type +// parameter, not its distributed representation. +declare function inferFromMapped(value: { [P in keyof T]: T[P] }): T; + +function f30(value: { [P in keyof U]: U[P] }, ordinary: U) { + const inferred = inferFromMapped(value); + const accept: typeof inferred = ordinary; +} + +// Inference to homomorphic mapped types nested in conditional types + +declare function inferInNonDistributive(x: [T] extends [object] ? { [K in keyof T]: () => T[K] } : never): T; +const inferredInNonDistributive = inferInNonDistributive({ a: () => 1 }); + +declare function inferInDistributive(x: T extends unknown ? { [K in keyof T]: () => T[K] } : never): T; +const inferredInDistributive = inferInDistributive({ a: () => 1 }); + +declare function inferFromMappedSelf(value: { [P in keyof T]: T }): T; +function f40(value: { [P in keyof U]: U }, ordinary: U) { + const inferred = inferFromMappedSelf(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedBox(value: { [P in keyof X]: Box }): T; +function f41(value: { [P in keyof U]: Box }, ordinary: U) { + const inferred = inferFromMappedBox(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedInlineObject(value: { [P in keyof X]: { value: T } }): T; +function f42(value: { [P in keyof U]: { value: U } }, ordinary: U) { + const inferred = inferFromMappedInlineObject(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedInlineFunction(value: { [P in keyof X]: (arg: T) => T }): T; +function f43(value: { [P in keyof U]: (arg: U) => U }, ordinary: U) { + const inferred = inferFromMappedInlineFunction(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedInlineIntersection(value: { [P in keyof X]: { a: T } & { b: T } }): T; +function f44(value: { [P in keyof U]: { a: U } & { b: U } }, ordinary: U) { + const inferred = inferFromMappedInlineIntersection(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedConditional(value: { [P in keyof X]: X[P] extends string ? { value: T } : never }): T; +function f45(value: { [P in keyof U]: U[P] extends string ? { value: U } : never }, ordinary: U) { + const inferred = inferFromMappedConditional(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromPlainTargetOfMapped(value: { a: { value: T } }): T; +function f46(value: { [P in keyof U]: { value: U } }, ordinary: U) { + const inferred = inferFromPlainTargetOfMapped(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromWrappedMapped(value: { wrap: { [P in keyof X]: { value: T } } }): T; +function f47(value: { wrap: { [P in keyof U]: { value: U } } }, ordinary: U) { + const inferred = inferFromWrappedMapped(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedCallbackParameter(cb: (arg: { [P in keyof X]: { value: T } }) => void): T; +function f48(cb: (arg: { [P in keyof U]: { value: U } }) => void, ordinary: U) { + const inferred = inferFromMappedCallbackParameter(cb); + const accept: typeof inferred = ordinary; +} + +declare function inferFromDeeplyNestedMapped(value: { [P in keyof X]: { a: { b: [() => T] } } }): T; +function f49(value: { [P in keyof U]: { a: { b: [() => U] } } }, ordinary: U) { + const inferred = inferFromDeeplyNestedMapped(value); + const accept: typeof inferred = ordinary; +} //// [isomorphicMappedTypeInference.js] @@ -298,6 +375,52 @@ function getProps(obj, list) { const myAny = {}; const o1 = getProps(myAny, ['foo', 'bar']); const o2 = getProps(myAny, ['foo', 'bar']); +function f30(value, ordinary) { + const inferred = inferFromMapped(value); + const accept = ordinary; +} +const inferredInNonDistributive = inferInNonDistributive({ a: () => 1 }); +const inferredInDistributive = inferInDistributive({ a: () => 1 }); +function f40(value, ordinary) { + const inferred = inferFromMappedSelf(value); + const accept = ordinary; +} +function f41(value, ordinary) { + const inferred = inferFromMappedBox(value); + const accept = ordinary; +} +function f42(value, ordinary) { + const inferred = inferFromMappedInlineObject(value); + const accept = ordinary; +} +function f43(value, ordinary) { + const inferred = inferFromMappedInlineFunction(value); + const accept = ordinary; +} +function f44(value, ordinary) { + const inferred = inferFromMappedInlineIntersection(value); + const accept = ordinary; +} +function f45(value, ordinary) { + const inferred = inferFromMappedConditional(value); + const accept = ordinary; +} +function f46(value, ordinary) { + const inferred = inferFromPlainTargetOfMapped(value); + const accept = ordinary; +} +function f47(value, ordinary) { + const inferred = inferFromWrappedMapped(value); + const accept = ordinary; +} +function f48(cb, ordinary) { + const inferred = inferFromMappedCallbackParameter(cb); + const accept = ordinary; +} +function f49(value, ordinary) { + const inferred = inferFromDeeplyNestedMapped(value); + const accept = ordinary; +} //// [isomorphicMappedTypeInference.d.ts] @@ -400,3 +523,123 @@ declare const o2: { foo: any; bar: any; }; +declare function inferFromMapped(value: { + [P in keyof T]: T[P]; +}): T; +declare function f30(value: { + [P in keyof U]: U[P]; +}, ordinary: U): void; +declare function inferInNonDistributive(x: [T] extends [object] ? { + [K in keyof T]: () => T[K]; +} : never): T; +declare const inferredInNonDistributive: { + a: number; +}; +declare function inferInDistributive(x: T extends unknown ? { + [K in keyof T]: () => T[K]; +} : never): T; +declare const inferredInDistributive: { + a: number; +}; +declare function inferFromMappedSelf(value: { + [P in keyof T]: T; +}): T; +declare function f40(value: { + [P in keyof U]: U; +}, ordinary: U): void; +declare function inferFromMappedBox(value: { + [P in keyof X]: Box; +}): T; +declare function f41(value: { + [P in keyof U]: Box; +}, ordinary: U): void; +declare function inferFromMappedInlineObject(value: { + [P in keyof X]: { + value: T; + }; +}): T; +declare function f42(value: { + [P in keyof U]: { + value: U; + }; +}, ordinary: U): void; +declare function inferFromMappedInlineFunction(value: { + [P in keyof X]: (arg: T) => T; +}): T; +declare function f43(value: { + [P in keyof U]: (arg: U) => U; +}, ordinary: U): void; +declare function inferFromMappedInlineIntersection(value: { + [P in keyof X]: { + a: T; + } & { + b: T; + }; +}): T; +declare function f44(value: { + [P in keyof U]: { + a: U; + } & { + b: U; + }; +}, ordinary: U): void; +declare function inferFromMappedConditional(value: { + [P in keyof X]: X[P] extends string ? { + value: T; + } : never; +}): T; +declare function f45(value: { + [P in keyof U]: U[P] extends string ? { + value: U; + } : never; +}, ordinary: U): void; +declare function inferFromPlainTargetOfMapped(value: { + a: { + value: T; + }; +}): T; +declare function f46(value: { + [P in keyof U]: { + value: U; + }; +}, ordinary: U): void; +declare function inferFromWrappedMapped(value: { + wrap: { + [P in keyof X]: { + value: T; + }; + }; +}): T; +declare function f47(value: { + wrap: { + [P in keyof U]: { + value: U; + }; + }; +}, ordinary: U): void; +declare function inferFromMappedCallbackParameter(cb: (arg: { + [P in keyof X]: { + value: T; + }; +}) => void): T; +declare function f48(cb: (arg: { + [P in keyof U]: { + value: U; + }; +}) => void, ordinary: U): void; +declare function inferFromDeeplyNestedMapped(value: { + [P in keyof X]: { + a: { + b: [() => T]; + }; + }; +}): T; +declare function f49(value: { + [P in keyof U]: { + a: { + b: [() => U]; + }; + }; +}, ordinary: U): void; diff --git a/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.symbols b/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.symbols index f48c4517b700d..84ef6fb429612 100644 --- a/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.symbols +++ b/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.symbols @@ -618,3 +618,413 @@ const o2: { foo: any; bar: any } = getProps(myAny, ['foo', 'bar']); >getProps : Symbol(getProps, Decl(isomorphicMappedTypeInference.ts, 165, 40)) >myAny : Symbol(myAny, Decl(isomorphicMappedTypeInference.ts, 173, 5)) +// Inference between homomorphic mapped types should infer the original type +// parameter, not its distributed representation. +declare function inferFromMapped(value: { [P in keyof T]: T[P] }): T; +>inferFromMapped : Symbol(inferFromMapped, Decl(isomorphicMappedTypeInference.ts, 177, 67)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 181, 33)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 181, 36)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 181, 46)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 181, 33)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 181, 33)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 181, 46)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 181, 33)) + +function f30(value: { [P in keyof U]: U[P] }, ordinary: U) { +>f30 : Symbol(f30, Decl(isomorphicMappedTypeInference.ts, 181, 72)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 183, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 183, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 183, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 183, 13)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 183, 13)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 183, 26)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 183, 48)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 183, 13)) + + const inferred = inferFromMapped(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 184, 9)) +>inferFromMapped : Symbol(inferFromMapped, Decl(isomorphicMappedTypeInference.ts, 177, 67)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 183, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 185, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 184, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 183, 48)) +} + +// Inference to homomorphic mapped types nested in conditional types + +declare function inferInNonDistributive(x: [T] extends [object] ? { [K in keyof T]: () => T[K] } : never): T; +>inferInNonDistributive : Symbol(inferInNonDistributive, Decl(isomorphicMappedTypeInference.ts, 186, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 190, 40)) +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 190, 43)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 190, 40)) +>K : Symbol(K, Decl(isomorphicMappedTypeInference.ts, 190, 72)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 190, 40)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 190, 40)) +>K : Symbol(K, Decl(isomorphicMappedTypeInference.ts, 190, 72)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 190, 40)) + +const inferredInNonDistributive = inferInNonDistributive({ a: () => 1 }); +>inferredInNonDistributive : Symbol(inferredInNonDistributive, Decl(isomorphicMappedTypeInference.ts, 191, 5)) +>inferInNonDistributive : Symbol(inferInNonDistributive, Decl(isomorphicMappedTypeInference.ts, 186, 1)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 191, 58)) + +declare function inferInDistributive(x: T extends unknown ? { [K in keyof T]: () => T[K] } : never): T; +>inferInDistributive : Symbol(inferInDistributive, Decl(isomorphicMappedTypeInference.ts, 191, 73)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 193, 37)) +>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 193, 40)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 193, 37)) +>K : Symbol(K, Decl(isomorphicMappedTypeInference.ts, 193, 66)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 193, 37)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 193, 37)) +>K : Symbol(K, Decl(isomorphicMappedTypeInference.ts, 193, 66)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 193, 37)) + +const inferredInDistributive = inferInDistributive({ a: () => 1 }); +>inferredInDistributive : Symbol(inferredInDistributive, Decl(isomorphicMappedTypeInference.ts, 194, 5)) +>inferInDistributive : Symbol(inferInDistributive, Decl(isomorphicMappedTypeInference.ts, 191, 73)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 194, 52)) + +declare function inferFromMappedSelf(value: { [P in keyof T]: T }): T; +>inferFromMappedSelf : Symbol(inferFromMappedSelf, Decl(isomorphicMappedTypeInference.ts, 194, 67)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 196, 37)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 196, 40)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 196, 50)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 196, 37)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 196, 37)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 196, 37)) + +function f40(value: { [P in keyof U]: U }, ordinary: U) { +>f40 : Symbol(f40, Decl(isomorphicMappedTypeInference.ts, 196, 73)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 197, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 197, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 197, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 197, 13)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 197, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 197, 45)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 197, 13)) + + const inferred = inferFromMappedSelf(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 198, 9)) +>inferFromMappedSelf : Symbol(inferFromMappedSelf, Decl(isomorphicMappedTypeInference.ts, 194, 67)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 197, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 199, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 198, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 197, 45)) +} + +declare function inferFromMappedBox(value: { [P in keyof X]: Box }): T; +>inferFromMappedBox : Symbol(inferFromMappedBox, Decl(isomorphicMappedTypeInference.ts, 200, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 202, 36)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 202, 38)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 202, 42)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 202, 52)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 202, 36)) +>Box : Symbol(Box, Decl(isomorphicMappedTypeInference.ts, 0, 0)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 202, 38)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 202, 38)) + +function f41(value: { [P in keyof U]: Box }, ordinary: U) { +>f41 : Symbol(f41, Decl(isomorphicMappedTypeInference.ts, 202, 80)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 203, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 203, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 203, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 203, 13)) +>Box : Symbol(Box, Decl(isomorphicMappedTypeInference.ts, 0, 0)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 203, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 203, 50)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 203, 13)) + + const inferred = inferFromMappedBox(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 204, 9)) +>inferFromMappedBox : Symbol(inferFromMappedBox, Decl(isomorphicMappedTypeInference.ts, 200, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 203, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 205, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 204, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 203, 50)) +} + +declare function inferFromMappedInlineObject(value: { [P in keyof X]: { value: T } }): T; +>inferFromMappedInlineObject : Symbol(inferFromMappedInlineObject, Decl(isomorphicMappedTypeInference.ts, 206, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 208, 45)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 208, 47)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 208, 51)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 208, 61)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 208, 45)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 208, 77)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 208, 47)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 208, 47)) + +function f42(value: { [P in keyof U]: { value: U } }, ordinary: U) { +>f42 : Symbol(f42, Decl(isomorphicMappedTypeInference.ts, 208, 95)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 209, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 209, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 209, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 209, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 209, 42)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 209, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 209, 56)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 209, 13)) + + const inferred = inferFromMappedInlineObject(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 210, 9)) +>inferFromMappedInlineObject : Symbol(inferFromMappedInlineObject, Decl(isomorphicMappedTypeInference.ts, 206, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 209, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 211, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 210, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 209, 56)) +} + +declare function inferFromMappedInlineFunction(value: { [P in keyof X]: (arg: T) => T }): T; +>inferFromMappedInlineFunction : Symbol(inferFromMappedInlineFunction, Decl(isomorphicMappedTypeInference.ts, 212, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 214, 47)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 214, 49)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 214, 53)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 214, 63)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 214, 47)) +>arg : Symbol(arg, Decl(isomorphicMappedTypeInference.ts, 214, 79)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 214, 49)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 214, 49)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 214, 49)) + +function f43(value: { [P in keyof U]: (arg: U) => U }, ordinary: U) { +>f43 : Symbol(f43, Decl(isomorphicMappedTypeInference.ts, 214, 98)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 215, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 215, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 215, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 215, 13)) +>arg : Symbol(arg, Decl(isomorphicMappedTypeInference.ts, 215, 42)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 215, 13)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 215, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 215, 57)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 215, 13)) + + const inferred = inferFromMappedInlineFunction(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 216, 9)) +>inferFromMappedInlineFunction : Symbol(inferFromMappedInlineFunction, Decl(isomorphicMappedTypeInference.ts, 212, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 215, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 217, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 216, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 215, 57)) +} + +declare function inferFromMappedInlineIntersection(value: { [P in keyof X]: { a: T } & { b: T } }): T; +>inferFromMappedInlineIntersection : Symbol(inferFromMappedInlineIntersection, Decl(isomorphicMappedTypeInference.ts, 218, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 220, 51)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 220, 53)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 220, 57)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 220, 67)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 220, 51)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 220, 83)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 220, 53)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 220, 94)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 220, 53)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 220, 53)) + +function f44(value: { [P in keyof U]: { a: U } & { b: U } }, ordinary: U) { +>f44 : Symbol(f44, Decl(isomorphicMappedTypeInference.ts, 220, 108)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 221, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 221, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 221, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 221, 13)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 221, 42)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 221, 13)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 221, 53)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 221, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 221, 63)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 221, 13)) + + const inferred = inferFromMappedInlineIntersection(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 222, 9)) +>inferFromMappedInlineIntersection : Symbol(inferFromMappedInlineIntersection, Decl(isomorphicMappedTypeInference.ts, 218, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 221, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 223, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 222, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 221, 63)) +} + +declare function inferFromMappedConditional(value: { [P in keyof X]: X[P] extends string ? { value: T } : never }): T; +>inferFromMappedConditional : Symbol(inferFromMappedConditional, Decl(isomorphicMappedTypeInference.ts, 224, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 226, 44)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 226, 46)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 226, 50)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 226, 60)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 226, 44)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 226, 44)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 226, 60)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 226, 98)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 226, 46)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 226, 46)) + +function f45(value: { [P in keyof U]: U[P] extends string ? { value: U } : never }, ordinary: U) { +>f45 : Symbol(f45, Decl(isomorphicMappedTypeInference.ts, 226, 124)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 227, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 227, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 227, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 227, 13)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 227, 13)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 227, 26)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 227, 64)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 227, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 227, 86)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 227, 13)) + + const inferred = inferFromMappedConditional(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 228, 9)) +>inferFromMappedConditional : Symbol(inferFromMappedConditional, Decl(isomorphicMappedTypeInference.ts, 224, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 227, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 229, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 228, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 227, 86)) +} + +declare function inferFromPlainTargetOfMapped(value: { a: { value: T } }): T; +>inferFromPlainTargetOfMapped : Symbol(inferFromPlainTargetOfMapped, Decl(isomorphicMappedTypeInference.ts, 230, 1)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 232, 46)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 232, 49)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 232, 57)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 232, 62)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 232, 46)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 232, 46)) + +function f46(value: { [P in keyof U]: { value: U } }, ordinary: U) { +>f46 : Symbol(f46, Decl(isomorphicMappedTypeInference.ts, 232, 80)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 233, 13)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 233, 24)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 233, 39)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 233, 49)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 233, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 233, 65)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 233, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 233, 79)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 233, 13)) + + const inferred = inferFromPlainTargetOfMapped(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 234, 9)) +>inferFromPlainTargetOfMapped : Symbol(inferFromPlainTargetOfMapped, Decl(isomorphicMappedTypeInference.ts, 230, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 233, 39)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 235, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 234, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 233, 79)) +} + +declare function inferFromWrappedMapped(value: { wrap: { [P in keyof X]: { value: T } } }): T; +>inferFromWrappedMapped : Symbol(inferFromWrappedMapped, Decl(isomorphicMappedTypeInference.ts, 236, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 238, 40)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 238, 42)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 238, 46)) +>wrap : Symbol(wrap, Decl(isomorphicMappedTypeInference.ts, 238, 54)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 238, 64)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 238, 40)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 238, 80)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 238, 42)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 238, 42)) + +function f47(value: { wrap: { [P in keyof U]: { value: U } } }, ordinary: U) { +>f47 : Symbol(f47, Decl(isomorphicMappedTypeInference.ts, 238, 100)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 239, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 239, 16)) +>wrap : Symbol(wrap, Decl(isomorphicMappedTypeInference.ts, 239, 24)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 239, 34)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 239, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 239, 50)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 239, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 239, 66)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 239, 13)) + + const inferred = inferFromWrappedMapped(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 240, 9)) +>inferFromWrappedMapped : Symbol(inferFromWrappedMapped, Decl(isomorphicMappedTypeInference.ts, 236, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 239, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 241, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 240, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 239, 66)) +} + +declare function inferFromMappedCallbackParameter(cb: (arg: { [P in keyof X]: { value: T } }) => void): T; +>inferFromMappedCallbackParameter : Symbol(inferFromMappedCallbackParameter, Decl(isomorphicMappedTypeInference.ts, 242, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 244, 50)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 244, 52)) +>cb : Symbol(cb, Decl(isomorphicMappedTypeInference.ts, 244, 56)) +>arg : Symbol(arg, Decl(isomorphicMappedTypeInference.ts, 244, 61)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 244, 69)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 244, 50)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 244, 85)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 244, 52)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 244, 52)) + +function f48(cb: (arg: { [P in keyof U]: { value: U } }) => void, ordinary: U) { +>f48 : Symbol(f48, Decl(isomorphicMappedTypeInference.ts, 244, 112)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 245, 13)) +>cb : Symbol(cb, Decl(isomorphicMappedTypeInference.ts, 245, 16)) +>arg : Symbol(arg, Decl(isomorphicMappedTypeInference.ts, 245, 21)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 245, 29)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 245, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 245, 45)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 245, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 245, 68)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 245, 13)) + + const inferred = inferFromMappedCallbackParameter(cb); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 246, 9)) +>inferFromMappedCallbackParameter : Symbol(inferFromMappedCallbackParameter, Decl(isomorphicMappedTypeInference.ts, 242, 1)) +>cb : Symbol(cb, Decl(isomorphicMappedTypeInference.ts, 245, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 247, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 246, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 245, 68)) +} + +declare function inferFromDeeplyNestedMapped(value: { [P in keyof X]: { a: { b: [() => T] } } }): T; +>inferFromDeeplyNestedMapped : Symbol(inferFromDeeplyNestedMapped, Decl(isomorphicMappedTypeInference.ts, 248, 1)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 250, 45)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 250, 47)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 250, 51)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 250, 61)) +>X : Symbol(X, Decl(isomorphicMappedTypeInference.ts, 250, 45)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 250, 77)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 250, 82)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 250, 47)) +>T : Symbol(T, Decl(isomorphicMappedTypeInference.ts, 250, 47)) + +function f49(value: { [P in keyof U]: { a: { b: [() => U] } } }, ordinary: U) { +>f49 : Symbol(f49, Decl(isomorphicMappedTypeInference.ts, 250, 106)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 251, 13)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 251, 16)) +>P : Symbol(P, Decl(isomorphicMappedTypeInference.ts, 251, 26)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 251, 13)) +>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 251, 42)) +>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 251, 47)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 251, 13)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 251, 67)) +>U : Symbol(U, Decl(isomorphicMappedTypeInference.ts, 251, 13)) + + const inferred = inferFromDeeplyNestedMapped(value); +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 252, 9)) +>inferFromDeeplyNestedMapped : Symbol(inferFromDeeplyNestedMapped, Decl(isomorphicMappedTypeInference.ts, 248, 1)) +>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 251, 16)) + + const accept: typeof inferred = ordinary; +>accept : Symbol(accept, Decl(isomorphicMappedTypeInference.ts, 253, 9)) +>inferred : Symbol(inferred, Decl(isomorphicMappedTypeInference.ts, 252, 9)) +>ordinary : Symbol(ordinary, Decl(isomorphicMappedTypeInference.ts, 251, 67)) +} + diff --git a/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.types b/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.types index d4b1193d05cff..8d314a37039e9 100644 --- a/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.types +++ b/tsc/testdata/baselines/reference/conformance/isomorphicMappedTypeInference.types @@ -622,3 +622,290 @@ const o2: { foo: any; bar: any } = getProps(myAny, ['foo', 'bar']); >'foo' : "foo" >'bar' : "bar" +// Inference between homomorphic mapped types should infer the original type +// parameter, not its distributed representation. +declare function inferFromMapped(value: { [P in keyof T]: T[P] }): T; +>inferFromMapped : (value: { [P in keyof T]: T[P]; }) => T +>value : { [P in keyof T]: T[P]; } + +function f30(value: { [P in keyof U]: U[P] }, ordinary: U) { +>f30 : (value: { [P in keyof U]: U[P]; }, ordinary: U) => void +>value : { [P in keyof U]: U[P]; } +>ordinary : U + + const inferred = inferFromMapped(value); +>inferred : U +>inferFromMapped(value) : U +>inferFromMapped : (value: { [P in keyof T]: T[P]; }) => T +>value : { [P in keyof U]: U[P]; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +// Inference to homomorphic mapped types nested in conditional types + +declare function inferInNonDistributive(x: [T] extends [object] ? { [K in keyof T]: () => T[K] } : never): T; +>inferInNonDistributive : (x: [T] extends [object] ? { [K in keyof T]: () => T[K]; } : never) => T +>x : [T] extends [object] ? { [K in keyof T]: () => T[K]; } : never + +const inferredInNonDistributive = inferInNonDistributive({ a: () => 1 }); +>inferredInNonDistributive : { a: number; } +>inferInNonDistributive({ a: () => 1 }) : { a: number; } +>inferInNonDistributive : (x: [T] extends [object] ? { [K in keyof T]: () => T[K]; } : never) => T +>{ a: () => 1 } : { a: () => number; } +>a : () => number +>() => 1 : () => number +>1 : 1 + +declare function inferInDistributive(x: T extends unknown ? { [K in keyof T]: () => T[K] } : never): T; +>inferInDistributive : (x: T extends unknown ? { [K in keyof T]: () => T[K]; } : never) => T +>x : T extends unknown ? { [K in keyof T]: () => T[K]; } : never + +const inferredInDistributive = inferInDistributive({ a: () => 1 }); +>inferredInDistributive : { a: number; } +>inferInDistributive({ a: () => 1 }) : { a: number; } +>inferInDistributive : (x: T extends unknown ? { [K in keyof T]: () => T[K]; } : never) => T +>{ a: () => 1 } : { a: () => number; } +>a : () => number +>() => 1 : () => number +>1 : 1 + +declare function inferFromMappedSelf(value: { [P in keyof T]: T }): T; +>inferFromMappedSelf : (value: { [P in keyof T]: T; }) => T +>value : { [P in keyof T]: T; } + +function f40(value: { [P in keyof U]: U }, ordinary: U) { +>f40 : (value: { [P in keyof U]: U; }, ordinary: U) => void +>value : { [P in keyof U]: U; } +>ordinary : U + + const inferred = inferFromMappedSelf(value); +>inferred : U +>inferFromMappedSelf(value) : U +>inferFromMappedSelf : (value: { [P in keyof T]: T; }) => T +>value : { [P in keyof U]: U; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromMappedBox(value: { [P in keyof X]: Box }): T; +>inferFromMappedBox : (value: { [P in keyof X]: Box; }) => T +>value : { [P in keyof X]: Box; } + +function f41(value: { [P in keyof U]: Box }, ordinary: U) { +>f41 : (value: { [P in keyof U]: Box; }, ordinary: U) => void +>value : { [P in keyof U]: Box; } +>ordinary : U + + const inferred = inferFromMappedBox(value); +>inferred : U +>inferFromMappedBox(value) : U +>inferFromMappedBox : (value: { [P in keyof X]: Box; }) => T +>value : { [P in keyof U]: Box; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromMappedInlineObject(value: { [P in keyof X]: { value: T } }): T; +>inferFromMappedInlineObject : (value: { [P in keyof X]: { value: T; }; }) => T +>value : { [P in keyof X]: { value: T; }; } +>value : T + +function f42(value: { [P in keyof U]: { value: U } }, ordinary: U) { +>f42 : (value: { [P in keyof U]: { value: U; }; }, ordinary: U) => void +>value : { [P in keyof U]: { value: U; }; } +>value : U +>ordinary : U + + const inferred = inferFromMappedInlineObject(value); +>inferred : U +>inferFromMappedInlineObject(value) : U +>inferFromMappedInlineObject : (value: { [P in keyof X]: { value: T; }; }) => T +>value : { [P in keyof U]: { value: U; }; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromMappedInlineFunction(value: { [P in keyof X]: (arg: T) => T }): T; +>inferFromMappedInlineFunction : (value: { [P in keyof X]: (arg: T) => T; }) => T +>value : { [P in keyof X]: (arg: T) => T; } +>arg : T + +function f43(value: { [P in keyof U]: (arg: U) => U }, ordinary: U) { +>f43 : (value: { [P in keyof U]: (arg: U) => U; }, ordinary: U) => void +>value : { [P in keyof U]: (arg: U) => U; } +>arg : U +>ordinary : U + + const inferred = inferFromMappedInlineFunction(value); +>inferred : U +>inferFromMappedInlineFunction(value) : U +>inferFromMappedInlineFunction : (value: { [P in keyof X]: (arg: T) => T; }) => T +>value : { [P in keyof U]: (arg: U) => U; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromMappedInlineIntersection(value: { [P in keyof X]: { a: T } & { b: T } }): T; +>inferFromMappedInlineIntersection : (value: { [P in keyof X]: { a: T; } & { b: T; }; }) => T +>value : { [P in keyof X]: { a: T; } & { b: T; }; } +>a : T +>b : T + +function f44(value: { [P in keyof U]: { a: U } & { b: U } }, ordinary: U) { +>f44 : (value: { [P in keyof U]: { a: U; } & { b: U; }; }, ordinary: U) => void +>value : { [P in keyof U]: { a: U; } & { b: U; }; } +>a : U +>b : U +>ordinary : U + + const inferred = inferFromMappedInlineIntersection(value); +>inferred : U +>inferFromMappedInlineIntersection(value) : U +>inferFromMappedInlineIntersection : (value: { [P in keyof X]: { a: T; } & { b: T; }; }) => T +>value : { [P in keyof U]: { a: U; } & { b: U; }; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromMappedConditional(value: { [P in keyof X]: X[P] extends string ? { value: T } : never }): T; +>inferFromMappedConditional : (value: { [P in keyof X]: X[P] extends string ? { value: T; } : never; }) => T +>value : { [P in keyof X]: X[P] extends string ? { value: T; } : never; } +>value : T + +function f45(value: { [P in keyof U]: U[P] extends string ? { value: U } : never }, ordinary: U) { +>f45 : (value: { [P in keyof U]: U[P] extends string ? { value: U; } : never; }, ordinary: U) => void +>value : { [P in keyof U]: U[P] extends string ? { value: U; } : never; } +>value : U +>ordinary : U + + const inferred = inferFromMappedConditional(value); +>inferred : U +>inferFromMappedConditional(value) : U +>inferFromMappedConditional : (value: { [P in keyof X]: X[P] extends string ? { value: T; } : never; }) => T +>value : { [P in keyof U]: U[P] extends string ? { value: U; } : never; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromPlainTargetOfMapped(value: { a: { value: T } }): T; +>inferFromPlainTargetOfMapped : (value: { a: { value: T; }; }) => T +>value : { a: { value: T; }; } +>a : { value: T; } +>value : T + +function f46(value: { [P in keyof U]: { value: U } }, ordinary: U) { +>f46 : (value: { [P in keyof U]: { value: U; }; }, ordinary: U) => void +>a : unknown +>value : { [P in keyof U]: { value: U; }; } +>value : U +>ordinary : U + + const inferred = inferFromPlainTargetOfMapped(value); +>inferred : U +>inferFromPlainTargetOfMapped(value) : U +>inferFromPlainTargetOfMapped : (value: { a: { value: T; }; }) => T +>value : { [P in keyof U]: { value: U; }; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromWrappedMapped(value: { wrap: { [P in keyof X]: { value: T } } }): T; +>inferFromWrappedMapped : (value: { wrap: { [P in keyof X]: { value: T; }; }; }) => T +>value : { wrap: { [P in keyof X]: { value: T; }; }; } +>wrap : { [P in keyof X]: { value: T; }; } +>value : T + +function f47(value: { wrap: { [P in keyof U]: { value: U } } }, ordinary: U) { +>f47 : (value: { wrap: { [P in keyof U]: { value: U; }; }; }, ordinary: U) => void +>value : { wrap: { [P in keyof U]: { value: U; }; }; } +>wrap : { [P in keyof U]: { value: U; }; } +>value : U +>ordinary : U + + const inferred = inferFromWrappedMapped(value); +>inferred : U +>inferFromWrappedMapped(value) : U +>inferFromWrappedMapped : (value: { wrap: { [P in keyof X]: { value: T; }; }; }) => T +>value : { wrap: { [P in keyof U]: { value: U; }; }; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromMappedCallbackParameter(cb: (arg: { [P in keyof X]: { value: T } }) => void): T; +>inferFromMappedCallbackParameter : (cb: (arg: { [P in keyof X]: { value: T; }; }) => void) => T +>cb : (arg: { [P in keyof X]: { value: T; }; }) => void +>arg : { [P in keyof X]: { value: T; }; } +>value : T + +function f48(cb: (arg: { [P in keyof U]: { value: U } }) => void, ordinary: U) { +>f48 : (cb: (arg: { [P in keyof U]: { value: U; }; }) => void, ordinary: U) => void +>cb : (arg: { [P in keyof U]: { value: U; }; }) => void +>arg : { [P in keyof U]: { value: U; }; } +>value : U +>ordinary : U + + const inferred = inferFromMappedCallbackParameter(cb); +>inferred : U +>inferFromMappedCallbackParameter(cb) : U +>inferFromMappedCallbackParameter : (cb: (arg: { [P in keyof X]: { value: T; }; }) => void) => T +>cb : (arg: { [P in keyof U]: { value: U; }; }) => void + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + +declare function inferFromDeeplyNestedMapped(value: { [P in keyof X]: { a: { b: [() => T] } } }): T; +>inferFromDeeplyNestedMapped : (value: { [P in keyof X]: { a: { b: [() => T]; }; }; }) => T +>value : { [P in keyof X]: { a: { b: [() => T]; }; }; } +>a : { b: [() => T]; } +>b : [() => T] + +function f49(value: { [P in keyof U]: { a: { b: [() => U] } } }, ordinary: U) { +>f49 : (value: { [P in keyof U]: { a: { b: [() => U]; }; }; }, ordinary: U) => void +>value : { [P in keyof U]: { a: { b: [() => U]; }; }; } +>a : { b: [() => U]; } +>b : [() => U] +>ordinary : U + + const inferred = inferFromDeeplyNestedMapped(value); +>inferred : U +>inferFromDeeplyNestedMapped(value) : U +>inferFromDeeplyNestedMapped : (value: { [P in keyof X]: { a: { b: [() => T]; }; }; }) => T +>value : { [P in keyof U]: { a: { b: [() => U]; }; }; } + + const accept: typeof inferred = ordinary; +>accept : U +>inferred : U +>ordinary : U +} + diff --git a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.errors.txt b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.errors.txt index 1918a9532f32d..19fc26b04d23b 100644 --- a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.errors.txt +++ b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.errors.txt @@ -71,9 +71,16 @@ mappedTypeRelationships.ts(168,5): error TS2322: Type '{ [P in K]: T[P]; }' is n Type 'T[P]' is not assignable to type 'U[P]'. Type 'T' is not assignable to type 'U'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. +mappedTypeRelationships.ts(264,5): error TS2322: Type 'T' is not assignable to type '{ [K in keyof T]: T; }'. +mappedTypeRelationships.ts(265,5): error TS2322: Type '{ [K in keyof T]: U; }' is not assignable to type '{ [K in keyof T]: T; }'. + Type 'U' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. +mappedTypeRelationships.ts(266,5): error TS2322: Type '{ [K in keyof T]: T; }' is not assignable to type '{ [K in keyof T]: U; }'. + Type 'T' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. -==== mappedTypeRelationships.ts (28 errors) ==== +==== mappedTypeRelationships.ts (31 errors) ==== function f1(x: T, k: keyof T) { return x[k]; } @@ -389,4 +396,96 @@ mappedTypeRelationships.ts(168,5): error TS2322: Type '{ [P in K]: T[P]; }' is n type ConcreteSettingsResult2 = Settings; type GenericSettingsAccess = Settings; type GenericSettingsResult1 = GenericSettingsAccess<"audio">; - type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; \ No newline at end of file + type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; + function mappedRelations1(x: { [K in keyof T]: [T, T[K]] }, y: { [K in keyof T]: [T, T[K]] }) { + x = y; + y = x; + } + + function mappedRelations2(x: { [K in keyof T]: { t: T, k: T[K] } }, y: { [K in keyof T]: { t: T, k: T[K] } }) { + x = y; + y = x; + } + + function mappedRelations3(x: { [K in keyof T]: (t: T) => T[K] }, y: { [K in keyof T]: (t: T) => T[K] }) { + x = y; + y = x; + } + + function mappedRelations4( + x: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, + y: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, + ) { + x = y; + y = x; + } + + function mappedRelations5(x: { [K in keyof T]: { t: T } }) { + const make = (v: V): { [K in keyof T]: { t: T, v: V } } => null!; + x = make(1); + } + + function mappedRelations6(x: T extends object ? { inner: { [K in keyof T]: T } } : never, y: { [K in keyof T]: T }) { + x.inner = y; + y = x.inner; + } + + interface MappedBox { value: X } + function mappedRelations7(x: MappedBox<{ [K in keyof T]: { t: T } }>, y: MappedBox<{ [K in keyof T]: { t: T } }>) { + x = y; + y = x; + } + + type MappedAlias = { [K in keyof T]: { t: T, k: T[K] } }; + type MappedRecursive = { [K in keyof T]: { next: MappedRecursive, t: T } }; + function mappedRelations8(x: MappedAlias, y: { [K in keyof T]: { t: T, k: T[K] } }) { + x = y; + y = x; + const make = (v: V): MappedAlias => null!; + x = make(1); + } + + function mappedRelations9(x: MappedRecursive, y: { [K in keyof T]: { next: MappedRecursive, t: T } }) { + x = y; + y = x; + } + + function mappedRelations10(x: { [K in keyof T]: T }, y: T, z: { [K in keyof T]: U }) { + x = y; + ~ +!!! error TS2322: Type 'T' is not assignable to type '{ [K in keyof T]: T; }'. +!!! related TS2208 mappedTypeRelationships.ts:263:28: This type parameter might need an `extends { [K in keyof T]: T; }` constraint. + x = z; + ~ +!!! error TS2322: Type '{ [K in keyof T]: U; }' is not assignable to type '{ [K in keyof T]: T; }'. +!!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. +!!! related TS2208 mappedTypeRelationships.ts:263:31: This type parameter might need an `extends T` constraint. + z = x; + ~ +!!! error TS2322: Type '{ [K in keyof T]: T; }' is not assignable to type '{ [K in keyof T]: U; }'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. +!!! related TS2208 mappedTypeRelationships.ts:263:28: This type parameter might need an `extends U` constraint. + } + + declare let mappedSignature1: (m: A, r: (a: { [K in keyof A]: A }) => void) => void; + let mappedSignature2: (m: A, r: (a: { [K in keyof A]: A }) => void) => void = mappedSignature1; + + type MappedSigA = { m(u: U): void }; + type MappedSigB = { m(u: U): void }; + declare const mappedSigs: MappedSigA | MappedSigB; + mappedSigs.m({}); + + function mappedRelations11() { + type M = { [K in keyof X]: X }; + var a: { [K in keyof T]: T }; + var a: M; + } + + class MappedCallbacks { + m(item: T, callbacks: { [K in keyof T]: (item: T) => void }, key: keyof T): void { + callbacks[key](item); + } + } + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.js b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.js index 2623aa0272717..9b33c57fdabee 100644 --- a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.js +++ b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.js @@ -209,7 +209,86 @@ type ConcreteSettingsResult1 = Settings; type ConcreteSettingsResult2 = Settings; type GenericSettingsAccess = Settings; type GenericSettingsResult1 = GenericSettingsAccess<"audio">; -type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; +type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; +function mappedRelations1(x: { [K in keyof T]: [T, T[K]] }, y: { [K in keyof T]: [T, T[K]] }) { + x = y; + y = x; +} + +function mappedRelations2(x: { [K in keyof T]: { t: T, k: T[K] } }, y: { [K in keyof T]: { t: T, k: T[K] } }) { + x = y; + y = x; +} + +function mappedRelations3(x: { [K in keyof T]: (t: T) => T[K] }, y: { [K in keyof T]: (t: T) => T[K] }) { + x = y; + y = x; +} + +function mappedRelations4( + x: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, + y: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, +) { + x = y; + y = x; +} + +function mappedRelations5(x: { [K in keyof T]: { t: T } }) { + const make = (v: V): { [K in keyof T]: { t: T, v: V } } => null!; + x = make(1); +} + +function mappedRelations6(x: T extends object ? { inner: { [K in keyof T]: T } } : never, y: { [K in keyof T]: T }) { + x.inner = y; + y = x.inner; +} + +interface MappedBox { value: X } +function mappedRelations7(x: MappedBox<{ [K in keyof T]: { t: T } }>, y: MappedBox<{ [K in keyof T]: { t: T } }>) { + x = y; + y = x; +} + +type MappedAlias = { [K in keyof T]: { t: T, k: T[K] } }; +type MappedRecursive = { [K in keyof T]: { next: MappedRecursive, t: T } }; +function mappedRelations8(x: MappedAlias, y: { [K in keyof T]: { t: T, k: T[K] } }) { + x = y; + y = x; + const make = (v: V): MappedAlias => null!; + x = make(1); +} + +function mappedRelations9(x: MappedRecursive, y: { [K in keyof T]: { next: MappedRecursive, t: T } }) { + x = y; + y = x; +} + +function mappedRelations10(x: { [K in keyof T]: T }, y: T, z: { [K in keyof T]: U }) { + x = y; + x = z; + z = x; +} + +declare let mappedSignature1: (m: A, r: (a: { [K in keyof A]: A }) => void) => void; +let mappedSignature2: (m: A, r: (a: { [K in keyof A]: A }) => void) => void = mappedSignature1; + +type MappedSigA = { m(u: U): void }; +type MappedSigB = { m(u: U): void }; +declare const mappedSigs: MappedSigA | MappedSigB; +mappedSigs.m({}); + +function mappedRelations11() { + type M = { [K in keyof X]: X }; + var a: { [K in keyof T]: T }; + var a: M; +} + +class MappedCallbacks { + m(item: T, callbacks: { [K in keyof T]: (item: T) => void }, key: keyof T): void { + callbacks[key](item); + } +} + //// [mappedTypeRelationships.js] "use strict"; @@ -346,6 +425,60 @@ function f90() { function f() { return undefined; } +function mappedRelations1(x, y) { + x = y; + y = x; +} +function mappedRelations2(x, y) { + x = y; + y = x; +} +function mappedRelations3(x, y) { + x = y; + y = x; +} +function mappedRelations4(x, y) { + x = y; + y = x; +} +function mappedRelations5(x) { + const make = (v) => null; + x = make(1); +} +function mappedRelations6(x, y) { + x.inner = y; + y = x.inner; +} +function mappedRelations7(x, y) { + x = y; + y = x; +} +function mappedRelations8(x, y) { + x = y; + y = x; + const make = (v) => null; + x = make(1); +} +function mappedRelations9(x, y) { + x = y; + y = x; +} +function mappedRelations10(x, y, z) { + x = y; + x = z; + z = x; +} +let mappedSignature2 = mappedSignature1; +mappedSigs.m({}); +function mappedRelations11() { + var a; + var a; +} +class MappedCallbacks { + m(item, callbacks, key) { + callbacks[key](item); + } +} //// [mappedTypeRelationships.d.ts] @@ -456,3 +589,113 @@ type ConcreteSettingsResult2 = Settings; type GenericSettingsAccess = Settings; type GenericSettingsResult1 = GenericSettingsAccess<"audio">; type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; +declare function mappedRelations1(x: { + [K in keyof T]: [T, T[K]]; +}, y: { + [K in keyof T]: [T, T[K]]; +}): void; +declare function mappedRelations2(x: { + [K in keyof T]: { + t: T; + k: T[K]; + }; +}, y: { + [K in keyof T]: { + t: T; + k: T[K]; + }; +}): void; +declare function mappedRelations3(x: { + [K in keyof T]: (t: T) => T[K]; +}, y: { + [K in keyof T]: (t: T) => T[K]; +}): void; +declare function mappedRelations4(x: { + [K in keyof T]: T[K] extends string ? { + t: T; + } : { + u: T; + }; +}, y: { + [K in keyof T]: T[K] extends string ? { + t: T; + } : { + u: T; + }; +}): void; +declare function mappedRelations5(x: { + [K in keyof T]: { + t: T; + }; +}): void; +declare function mappedRelations6(x: T extends object ? { + inner: { + [K in keyof T]: T; + }; +} : never, y: { + [K in keyof T]: T; +}): void; +interface MappedBox { + value: X; +} +declare function mappedRelations7(x: MappedBox<{ + [K in keyof T]: { + t: T; + }; +}>, y: MappedBox<{ + [K in keyof T]: { + t: T; + }; +}>): void; +type MappedAlias = { + [K in keyof T]: { + t: T; + k: T[K]; + }; +}; +type MappedRecursive = { + [K in keyof T]: { + next: MappedRecursive; + t: T; + }; +}; +declare function mappedRelations8(x: MappedAlias, y: { + [K in keyof T]: { + t: T; + k: T[K]; + }; +}): void; +declare function mappedRelations9(x: MappedRecursive, y: { + [K in keyof T]: { + next: MappedRecursive; + t: T; + }; +}): void; +declare function mappedRelations10(x: { + [K in keyof T]: T; +}, y: T, z: { + [K in keyof T]: U; +}): void; +declare let mappedSignature1: (m: A, r: (a: { + [K in keyof A]: A; +}) => void) => void; +declare let mappedSignature2: (m: A, r: (a: { + [K in keyof A]: A; +}) => void) => void; +type MappedSigA = { + m(u: U): void; +}; +type MappedSigB = { + m(u: U): void; +}; +declare const mappedSigs: MappedSigA | MappedSigB; +declare function mappedRelations11(): void; +declare class MappedCallbacks { + m(item: T, callbacks: { + [K in keyof T]: (item: T) => void; + }, key: keyof T): void; +} diff --git a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.symbols b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.symbols index 3b992e02aa8e2..fc0f6a61d5adc 100644 --- a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.symbols +++ b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.symbols @@ -893,3 +893,415 @@ type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; >GenericSettingsResult2 : Symbol(GenericSettingsResult2, Decl(mappedTypeRelationships.ts, 207, 61)) >GenericSettingsAccess : Symbol(GenericSettingsAccess, Decl(mappedTypeRelationships.ts, 205, 74)) +function mappedRelations1(x: { [K in keyof T]: [T, T[K]] }, y: { [K in keyof T]: [T, T[K]] }) { +>mappedRelations1 : Symbol(mappedRelations1, Decl(mappedTypeRelationships.ts, 208, 71)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 209, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 209, 29)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 209, 35)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 209, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 209, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 209, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 209, 35)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 209, 62)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 209, 69)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 209, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 209, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 209, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 209, 69)) + + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 209, 29)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 209, 62)) + + y = x; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 209, 62)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 209, 29)) +} + +function mappedRelations2(x: { [K in keyof T]: { t: T, k: T[K] } }, y: { [K in keyof T]: { t: T, k: T[K] } }) { +>mappedRelations2 : Symbol(mappedRelations2, Decl(mappedTypeRelationships.ts, 212, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 214, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 214, 29)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 214, 35)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 214, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 214, 51)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 214, 26)) +>k : Symbol(k, Decl(mappedTypeRelationships.ts, 214, 57)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 214, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 214, 35)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 214, 70)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 214, 77)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 214, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 214, 93)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 214, 26)) +>k : Symbol(k, Decl(mappedTypeRelationships.ts, 214, 99)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 214, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 214, 77)) + + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 214, 29)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 214, 70)) + + y = x; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 214, 70)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 214, 29)) +} + +function mappedRelations3(x: { [K in keyof T]: (t: T) => T[K] }, y: { [K in keyof T]: (t: T) => T[K] }) { +>mappedRelations3 : Symbol(mappedRelations3, Decl(mappedTypeRelationships.ts, 217, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 219, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 219, 29)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 219, 35)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 219, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 219, 51)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 219, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 219, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 219, 35)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 219, 67)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 219, 74)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 219, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 219, 90)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 219, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 219, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 219, 74)) + + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 219, 29)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 219, 67)) + + y = x; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 219, 67)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 219, 29)) +} + +function mappedRelations4( +>mappedRelations4 : Symbol(mappedRelations4, Decl(mappedTypeRelationships.ts, 222, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) + + x: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 224, 29)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 225, 10)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 225, 10)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 225, 48)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) +>u : Symbol(u, Decl(mappedTypeRelationships.ts, 225, 59)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) + + y: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 225, 69)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 226, 10)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 226, 10)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 226, 48)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) +>u : Symbol(u, Decl(mappedTypeRelationships.ts, 226, 59)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 224, 26)) + +) { + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 224, 29)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 225, 69)) + + y = x; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 225, 69)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 224, 29)) +} + +function mappedRelations5(x: { [K in keyof T]: { t: T } }) { +>mappedRelations5 : Symbol(mappedRelations5, Decl(mappedTypeRelationships.ts, 230, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 232, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 232, 29)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 232, 35)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 232, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 232, 51)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 232, 26)) + + const make = (v: V): { [K in keyof T]: { t: T, v: V } } => null!; +>make : Symbol(make, Decl(mappedTypeRelationships.ts, 233, 9)) +>V : Symbol(V, Decl(mappedTypeRelationships.ts, 233, 18)) +>v : Symbol(v, Decl(mappedTypeRelationships.ts, 233, 21)) +>V : Symbol(V, Decl(mappedTypeRelationships.ts, 233, 18)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 233, 31)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 232, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 233, 47)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 232, 26)) +>v : Symbol(v, Decl(mappedTypeRelationships.ts, 233, 53)) +>V : Symbol(V, Decl(mappedTypeRelationships.ts, 233, 18)) + + x = make(1); +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 232, 29)) +>make : Symbol(make, Decl(mappedTypeRelationships.ts, 233, 9)) +} + +function mappedRelations6(x: T extends object ? { inner: { [K in keyof T]: T } } : never, y: { [K in keyof T]: T }) { +>mappedRelations6 : Symbol(mappedRelations6, Decl(mappedTypeRelationships.ts, 235, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 237, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 237, 29)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 237, 26)) +>inner : Symbol(inner, Decl(mappedTypeRelationships.ts, 237, 52)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 237, 63)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 237, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 237, 26)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 237, 92)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 237, 99)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 237, 26)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 237, 26)) + + x.inner = y; +>x.inner : Symbol(inner, Decl(mappedTypeRelationships.ts, 237, 52)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 237, 29)) +>inner : Symbol(inner, Decl(mappedTypeRelationships.ts, 237, 52)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 237, 92)) + + y = x.inner; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 237, 92)) +>x.inner : Symbol(inner, Decl(mappedTypeRelationships.ts, 237, 52)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 237, 29)) +>inner : Symbol(inner, Decl(mappedTypeRelationships.ts, 237, 52)) +} + +interface MappedBox { value: X } +>MappedBox : Symbol(MappedBox, Decl(mappedTypeRelationships.ts, 240, 1)) +>X : Symbol(X, Decl(mappedTypeRelationships.ts, 242, 20)) +>value : Symbol(MappedBox.value, Decl(mappedTypeRelationships.ts, 242, 24)) +>X : Symbol(X, Decl(mappedTypeRelationships.ts, 242, 20)) + +function mappedRelations7(x: MappedBox<{ [K in keyof T]: { t: T } }>, y: MappedBox<{ [K in keyof T]: { t: T } }>) { +>mappedRelations7 : Symbol(mappedRelations7, Decl(mappedTypeRelationships.ts, 242, 35)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 243, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 243, 29)) +>MappedBox : Symbol(MappedBox, Decl(mappedTypeRelationships.ts, 240, 1)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 243, 45)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 243, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 243, 61)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 243, 26)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 243, 72)) +>MappedBox : Symbol(MappedBox, Decl(mappedTypeRelationships.ts, 240, 1)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 243, 89)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 243, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 243, 105)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 243, 26)) + + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 243, 29)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 243, 72)) + + y = x; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 243, 72)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 243, 29)) +} + +type MappedAlias = { [K in keyof T]: { t: T, k: T[K] } }; +>MappedAlias : Symbol(MappedAlias, Decl(mappedTypeRelationships.ts, 246, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 248, 17)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 248, 25)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 248, 17)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 248, 41)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 248, 17)) +>k : Symbol(k, Decl(mappedTypeRelationships.ts, 248, 47)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 248, 17)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 248, 25)) + +type MappedRecursive = { [K in keyof T]: { next: MappedRecursive, t: T } }; +>MappedRecursive : Symbol(MappedRecursive, Decl(mappedTypeRelationships.ts, 248, 60)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 249, 21)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 249, 29)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 249, 21)) +>next : Symbol(next, Decl(mappedTypeRelationships.ts, 249, 45)) +>MappedRecursive : Symbol(MappedRecursive, Decl(mappedTypeRelationships.ts, 248, 60)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 249, 21)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 249, 71)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 249, 21)) + +function mappedRelations8(x: MappedAlias, y: { [K in keyof T]: { t: T, k: T[K] } }) { +>mappedRelations8 : Symbol(mappedRelations8, Decl(mappedTypeRelationships.ts, 249, 81)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 250, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 250, 29)) +>MappedAlias : Symbol(MappedAlias, Decl(mappedTypeRelationships.ts, 246, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 250, 26)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 250, 47)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 250, 54)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 250, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 250, 70)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 250, 26)) +>k : Symbol(k, Decl(mappedTypeRelationships.ts, 250, 76)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 250, 26)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 250, 54)) + + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 250, 29)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 250, 47)) + + y = x; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 250, 47)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 250, 29)) + + const make = (v: V): MappedAlias => null!; +>make : Symbol(make, Decl(mappedTypeRelationships.ts, 253, 9)) +>V : Symbol(V, Decl(mappedTypeRelationships.ts, 253, 18)) +>v : Symbol(v, Decl(mappedTypeRelationships.ts, 253, 21)) +>V : Symbol(V, Decl(mappedTypeRelationships.ts, 253, 18)) +>MappedAlias : Symbol(MappedAlias, Decl(mappedTypeRelationships.ts, 246, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 250, 26)) + + x = make(1); +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 250, 29)) +>make : Symbol(make, Decl(mappedTypeRelationships.ts, 253, 9)) +} + +function mappedRelations9(x: MappedRecursive, y: { [K in keyof T]: { next: MappedRecursive, t: T } }) { +>mappedRelations9 : Symbol(mappedRelations9, Decl(mappedTypeRelationships.ts, 255, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 257, 26)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 257, 29)) +>MappedRecursive : Symbol(MappedRecursive, Decl(mappedTypeRelationships.ts, 248, 60)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 257, 26)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 257, 51)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 257, 58)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 257, 26)) +>next : Symbol(next, Decl(mappedTypeRelationships.ts, 257, 74)) +>MappedRecursive : Symbol(MappedRecursive, Decl(mappedTypeRelationships.ts, 248, 60)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 257, 26)) +>t : Symbol(t, Decl(mappedTypeRelationships.ts, 257, 100)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 257, 26)) + + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 257, 29)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 257, 51)) + + y = x; +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 257, 51)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 257, 29)) +} + +function mappedRelations10(x: { [K in keyof T]: T }, y: T, z: { [K in keyof T]: U }) { +>mappedRelations10 : Symbol(mappedRelations10, Decl(mappedTypeRelationships.ts, 260, 1)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 262, 27)) +>U : Symbol(U, Decl(mappedTypeRelationships.ts, 262, 29)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 262, 33)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 262, 39)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 262, 27)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 262, 27)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 262, 58)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 262, 27)) +>z : Symbol(z, Decl(mappedTypeRelationships.ts, 262, 64)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 262, 71)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 262, 27)) +>U : Symbol(U, Decl(mappedTypeRelationships.ts, 262, 29)) + + x = y; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 262, 33)) +>y : Symbol(y, Decl(mappedTypeRelationships.ts, 262, 58)) + + x = z; +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 262, 33)) +>z : Symbol(z, Decl(mappedTypeRelationships.ts, 262, 64)) + + z = x; +>z : Symbol(z, Decl(mappedTypeRelationships.ts, 262, 64)) +>x : Symbol(x, Decl(mappedTypeRelationships.ts, 262, 33)) +} + +declare let mappedSignature1: (m: A, r: (a: { [K in keyof A]: A }) => void) => void; +>mappedSignature1 : Symbol(mappedSignature1, Decl(mappedTypeRelationships.ts, 268, 11)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 268, 31)) +>m : Symbol(m, Decl(mappedTypeRelationships.ts, 268, 34)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 268, 31)) +>r : Symbol(r, Decl(mappedTypeRelationships.ts, 268, 39)) +>a : Symbol(a, Decl(mappedTypeRelationships.ts, 268, 44)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 268, 50)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 268, 31)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 268, 31)) + +let mappedSignature2: (m: A, r: (a: { [K in keyof A]: A }) => void) => void = mappedSignature1; +>mappedSignature2 : Symbol(mappedSignature2, Decl(mappedTypeRelationships.ts, 269, 3)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 269, 23)) +>m : Symbol(m, Decl(mappedTypeRelationships.ts, 269, 26)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 269, 23)) +>r : Symbol(r, Decl(mappedTypeRelationships.ts, 269, 31)) +>a : Symbol(a, Decl(mappedTypeRelationships.ts, 269, 36)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 269, 42)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 269, 23)) +>A : Symbol(A, Decl(mappedTypeRelationships.ts, 269, 23)) +>mappedSignature1 : Symbol(mappedSignature1, Decl(mappedTypeRelationships.ts, 268, 11)) + +type MappedSigA = { m(u: U): void }; +>MappedSigA : Symbol(MappedSigA, Decl(mappedTypeRelationships.ts, 269, 98)) +>m : Symbol(m, Decl(mappedTypeRelationships.ts, 271, 19)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 271, 22)) +>U : Symbol(U, Decl(mappedTypeRelationships.ts, 271, 24)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 271, 38)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 271, 22)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 271, 22)) +>u : Symbol(u, Decl(mappedTypeRelationships.ts, 271, 58)) +>U : Symbol(U, Decl(mappedTypeRelationships.ts, 271, 24)) + +type MappedSigB = { m(u: U): void }; +>MappedSigB : Symbol(MappedSigB, Decl(mappedTypeRelationships.ts, 271, 72)) +>m : Symbol(m, Decl(mappedTypeRelationships.ts, 272, 19)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 272, 22)) +>U : Symbol(U, Decl(mappedTypeRelationships.ts, 272, 24)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 272, 38)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 272, 22)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 272, 22)) +>u : Symbol(u, Decl(mappedTypeRelationships.ts, 272, 58)) +>U : Symbol(U, Decl(mappedTypeRelationships.ts, 272, 24)) + +declare const mappedSigs: MappedSigA | MappedSigB; +>mappedSigs : Symbol(mappedSigs, Decl(mappedTypeRelationships.ts, 273, 13)) +>MappedSigA : Symbol(MappedSigA, Decl(mappedTypeRelationships.ts, 269, 98)) +>MappedSigB : Symbol(MappedSigB, Decl(mappedTypeRelationships.ts, 271, 72)) + +mappedSigs.m({}); +>mappedSigs.m : Symbol(m, Decl(mappedTypeRelationships.ts, 271, 19), Decl(mappedTypeRelationships.ts, 272, 19)) +>mappedSigs : Symbol(mappedSigs, Decl(mappedTypeRelationships.ts, 273, 13)) +>m : Symbol(m, Decl(mappedTypeRelationships.ts, 271, 19), Decl(mappedTypeRelationships.ts, 272, 19)) + +function mappedRelations11() { +>mappedRelations11 : Symbol(mappedRelations11, Decl(mappedTypeRelationships.ts, 274, 17)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 276, 27)) + + type M = { [K in keyof X]: X }; +>M : Symbol(M, Decl(mappedTypeRelationships.ts, 276, 33)) +>X : Symbol(X, Decl(mappedTypeRelationships.ts, 277, 11)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 277, 19)) +>X : Symbol(X, Decl(mappedTypeRelationships.ts, 277, 11)) +>X : Symbol(X, Decl(mappedTypeRelationships.ts, 277, 11)) + + var a: { [K in keyof T]: T }; +>a : Symbol(a, Decl(mappedTypeRelationships.ts, 278, 7), Decl(mappedTypeRelationships.ts, 279, 7)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 278, 14)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 276, 27)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 276, 27)) + + var a: M; +>a : Symbol(a, Decl(mappedTypeRelationships.ts, 278, 7), Decl(mappedTypeRelationships.ts, 279, 7)) +>M : Symbol(M, Decl(mappedTypeRelationships.ts, 276, 33)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 276, 27)) +} + +class MappedCallbacks { +>MappedCallbacks : Symbol(MappedCallbacks, Decl(mappedTypeRelationships.ts, 280, 1)) + + m(item: T, callbacks: { [K in keyof T]: (item: T) => void }, key: keyof T): void { +>m : Symbol(MappedCallbacks.m, Decl(mappedTypeRelationships.ts, 282, 23)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 283, 6)) +>item : Symbol(item, Decl(mappedTypeRelationships.ts, 283, 9)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 283, 6)) +>callbacks : Symbol(callbacks, Decl(mappedTypeRelationships.ts, 283, 17)) +>K : Symbol(K, Decl(mappedTypeRelationships.ts, 283, 32)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 283, 6)) +>item : Symbol(item, Decl(mappedTypeRelationships.ts, 283, 48)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 283, 6)) +>key : Symbol(key, Decl(mappedTypeRelationships.ts, 283, 67)) +>T : Symbol(T, Decl(mappedTypeRelationships.ts, 283, 6)) + + callbacks[key](item); +>callbacks : Symbol(callbacks, Decl(mappedTypeRelationships.ts, 283, 17)) +>key : Symbol(key, Decl(mappedTypeRelationships.ts, 283, 67)) +>item : Symbol(item, Decl(mappedTypeRelationships.ts, 283, 9)) + } +} + diff --git a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.types b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.types index 8f30993f2c0f5..3e01fd5e4b1e4 100644 --- a/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.types +++ b/tsc/testdata/baselines/reference/conformance/mappedTypeRelationships.types @@ -716,3 +716,291 @@ type GenericSettingsResult1 = GenericSettingsAccess<"audio">; type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; >GenericSettingsResult2 : GenericSettingsResult2 +function mappedRelations1(x: { [K in keyof T]: [T, T[K]] }, y: { [K in keyof T]: [T, T[K]] }) { +>mappedRelations1 : (x: { [K in keyof T]: [T, T[K]]; }, y: { [K in keyof T]: [T, T[K]]; }) => void +>x : { [K in keyof T]: [T, T[K]]; } +>y : { [K in keyof T]: [T, T[K]]; } + + x = y; +>x = y : { [K in keyof T]: [T, T[K]]; } +>x : { [K in keyof T]: [T, T[K]]; } +>y : { [K in keyof T]: [T, T[K]]; } + + y = x; +>y = x : { [K in keyof T]: [T, T[K]]; } +>y : { [K in keyof T]: [T, T[K]]; } +>x : { [K in keyof T]: [T, T[K]]; } +} + +function mappedRelations2(x: { [K in keyof T]: { t: T, k: T[K] } }, y: { [K in keyof T]: { t: T, k: T[K] } }) { +>mappedRelations2 : (x: { [K in keyof T]: { t: T; k: T[K]; }; }, y: { [K in keyof T]: { t: T; k: T[K]; }; }) => void +>x : { [K in keyof T]: { t: T; k: T[K]; }; } +>t : T +>k : T[K] +>y : { [K in keyof T]: { t: T; k: T[K]; }; } +>t : T +>k : T[K] + + x = y; +>x = y : { [K in keyof T]: { t: T; k: T[K]; }; } +>x : { [K in keyof T]: { t: T; k: T[K]; }; } +>y : { [K in keyof T]: { t: T; k: T[K]; }; } + + y = x; +>y = x : { [K in keyof T]: { t: T; k: T[K]; }; } +>y : { [K in keyof T]: { t: T; k: T[K]; }; } +>x : { [K in keyof T]: { t: T; k: T[K]; }; } +} + +function mappedRelations3(x: { [K in keyof T]: (t: T) => T[K] }, y: { [K in keyof T]: (t: T) => T[K] }) { +>mappedRelations3 : (x: { [K in keyof T]: (t: T) => T[K]; }, y: { [K in keyof T]: (t: T) => T[K]; }) => void +>x : { [K in keyof T]: (t: T) => T[K]; } +>t : T +>y : { [K in keyof T]: (t: T) => T[K]; } +>t : T + + x = y; +>x = y : { [K in keyof T]: (t: T) => T[K]; } +>x : { [K in keyof T]: (t: T) => T[K]; } +>y : { [K in keyof T]: (t: T) => T[K]; } + + y = x; +>y = x : { [K in keyof T]: (t: T) => T[K]; } +>y : { [K in keyof T]: (t: T) => T[K]; } +>x : { [K in keyof T]: (t: T) => T[K]; } +} + +function mappedRelations4( +>mappedRelations4 : (x: { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; }, y: { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; }) => void + + x: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, +>x : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } +>t : T +>u : T + + y: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, +>y : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } +>t : T +>u : T + +) { + x = y; +>x = y : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } +>x : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } +>y : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } + + y = x; +>y = x : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } +>y : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } +>x : { [K in keyof T]: T[K] extends string ? { t: T; } : { u: T; }; } +} + +function mappedRelations5(x: { [K in keyof T]: { t: T } }) { +>mappedRelations5 : (x: { [K in keyof T]: { t: T; }; }) => void +>x : { [K in keyof T]: { t: T; }; } +>t : T + + const make = (v: V): { [K in keyof T]: { t: T, v: V } } => null!; +>make : (v: V) => { [K in keyof T]: { t: T; v: V; }; } +>(v: V): { [K in keyof T]: { t: T, v: V } } => null! : (v: V) => { [K in keyof T]: { t: T; v: V; }; } +>v : V +>t : T +>v : V +>null! : never + + x = make(1); +>x = make(1) : { [K in keyof T]: { t: T; v: number; }; } +>x : { [K in keyof T]: { t: T; }; } +>make(1) : { [K in keyof T]: { t: T; v: number; }; } +>make : (v: V) => { [K in keyof T]: { t: T; v: V; }; } +>1 : 1 +} + +function mappedRelations6(x: T extends object ? { inner: { [K in keyof T]: T } } : never, y: { [K in keyof T]: T }) { +>mappedRelations6 : (x: T extends object ? { inner: { [K in keyof T]: T; }; } : never, y: { [K in keyof T]: T; }) => void +>x : T extends object ? { inner: { [K in keyof T]: T; }; } : never +>inner : { [K in keyof T]: T; } +>y : { [K in keyof T]: T; } + + x.inner = y; +>x.inner = y : { [K in keyof T]: T; } +>x.inner : { [K in keyof T]: T; } +>x : T extends object ? { inner: { [K in keyof T]: T; }; } : never +>inner : { [K in keyof T]: T; } +>y : { [K in keyof T]: T; } + + y = x.inner; +>y = x.inner : { [K in keyof T]: T; } +>y : { [K in keyof T]: T; } +>x.inner : { [K in keyof T]: T; } +>x : T extends object ? { inner: { [K in keyof T]: T; }; } : never +>inner : { [K in keyof T]: T; } +} + +interface MappedBox { value: X } +>value : X + +function mappedRelations7(x: MappedBox<{ [K in keyof T]: { t: T } }>, y: MappedBox<{ [K in keyof T]: { t: T } }>) { +>mappedRelations7 : (x: MappedBox<{ [K in keyof T]: { t: T; }; }>, y: MappedBox<{ [K in keyof T]: { t: T; }; }>) => void +>x : MappedBox<{ [K in keyof T]: { t: T; }; }> +>t : T +>y : MappedBox<{ [K in keyof T]: { t: T; }; }> +>t : T + + x = y; +>x = y : MappedBox<{ [K in keyof T]: { t: T; }; }> +>x : MappedBox<{ [K in keyof T]: { t: T; }; }> +>y : MappedBox<{ [K in keyof T]: { t: T; }; }> + + y = x; +>y = x : MappedBox<{ [K in keyof T]: { t: T; }; }> +>y : MappedBox<{ [K in keyof T]: { t: T; }; }> +>x : MappedBox<{ [K in keyof T]: { t: T; }; }> +} + +type MappedAlias = { [K in keyof T]: { t: T, k: T[K] } }; +>MappedAlias : MappedAlias +>t : T +>k : T[K] + +type MappedRecursive = { [K in keyof T]: { next: MappedRecursive, t: T } }; +>MappedRecursive : MappedRecursive +>next : MappedRecursive +>t : T + +function mappedRelations8(x: MappedAlias, y: { [K in keyof T]: { t: T, k: T[K] } }) { +>mappedRelations8 : (x: MappedAlias, y: { [K in keyof T]: { t: T; k: T[K]; }; }) => void +>x : MappedAlias +>y : { [K in keyof T]: { t: T; k: T[K]; }; } +>t : T +>k : T[K] + + x = y; +>x = y : { [K in keyof T]: { t: T; k: T[K]; }; } +>x : MappedAlias +>y : { [K in keyof T]: { t: T; k: T[K]; }; } + + y = x; +>y = x : MappedAlias +>y : { [K in keyof T]: { t: T; k: T[K]; }; } +>x : MappedAlias + + const make = (v: V): MappedAlias => null!; +>make : (v: V) => MappedAlias +>(v: V): MappedAlias => null! : (v: V) => MappedAlias +>v : V +>null! : never + + x = make(1); +>x = make(1) : MappedAlias +>x : MappedAlias +>make(1) : MappedAlias +>make : (v: V) => MappedAlias +>1 : 1 +} + +function mappedRelations9(x: MappedRecursive, y: { [K in keyof T]: { next: MappedRecursive, t: T } }) { +>mappedRelations9 : (x: MappedRecursive, y: { [K in keyof T]: { next: MappedRecursive; t: T; }; }) => void +>x : MappedRecursive +>y : { [K in keyof T]: { next: MappedRecursive; t: T; }; } +>next : MappedRecursive +>t : T + + x = y; +>x = y : { [K in keyof T]: { next: MappedRecursive; t: T; }; } +>x : MappedRecursive +>y : { [K in keyof T]: { next: MappedRecursive; t: T; }; } + + y = x; +>y = x : MappedRecursive +>y : { [K in keyof T]: { next: MappedRecursive; t: T; }; } +>x : MappedRecursive +} + +function mappedRelations10(x: { [K in keyof T]: T }, y: T, z: { [K in keyof T]: U }) { +>mappedRelations10 : (x: { [K in keyof T]: T; }, y: T, z: { [K in keyof T]: U; }) => void +>x : { [K in keyof T]: T; } +>y : T +>z : { [K in keyof T]: U; } + + x = y; +>x = y : T +>x : { [K in keyof T]: T; } +>y : T + + x = z; +>x = z : { [K in keyof T]: U; } +>x : { [K in keyof T]: T; } +>z : { [K in keyof T]: U; } + + z = x; +>z = x : { [K in keyof T]: T; } +>z : { [K in keyof T]: U; } +>x : { [K in keyof T]: T; } +} + +declare let mappedSignature1: (m: A, r: (a: { [K in keyof A]: A }) => void) => void; +>mappedSignature1 : (m: A, r: (a: { [K in keyof A]: A; }) => void) => void +>m : A +>r : (a: { [K in keyof A]: A; }) => void +>a : { [K in keyof A]: A; } + +let mappedSignature2: (m: A, r: (a: { [K in keyof A]: A }) => void) => void = mappedSignature1; +>mappedSignature2 : (m: A, r: (a: { [K in keyof A]: A; }) => void) => void +>m : A +>r : (a: { [K in keyof A]: A; }) => void +>a : { [K in keyof A]: A; } +>mappedSignature1 : (m: A, r: (a: { [K in keyof A]: A; }) => void) => void + +type MappedSigA = { m(u: U): void }; +>MappedSigA : MappedSigA +>m : (u: U) => void +>u : U + +type MappedSigB = { m(u: U): void }; +>MappedSigB : MappedSigB +>m : (u: U) => void +>u : U + +declare const mappedSigs: MappedSigA | MappedSigB; +>mappedSigs : MappedSigA | MappedSigB + +mappedSigs.m({}); +>mappedSigs.m({}) : void +>mappedSigs.m : ((u: U) => void) | ((u: U) => void) +>mappedSigs : MappedSigA | MappedSigB +>m : ((u: U) => void) | ((u: U) => void) +>{} : {} + +function mappedRelations11() { +>mappedRelations11 : () => void + + type M = { [K in keyof X]: X }; +>M : { [K in keyof X]: X; } + + var a: { [K in keyof T]: T }; +>a : { [K in keyof T]: T; } + + var a: M; +>a : { [K in keyof T]: T; } +} + +class MappedCallbacks { +>MappedCallbacks : MappedCallbacks + + m(item: T, callbacks: { [K in keyof T]: (item: T) => void }, key: keyof T): void { +>m : (item: T, callbacks: { [K in keyof T]: (item: T) => void; }, key: keyof T) => void +>item : T +>callbacks : { [K in keyof T]: (item: T) => void; } +>item : T +>key : keyof T + + callbacks[key](item); +>callbacks[key](item) : void +>callbacks[key] : { [K in keyof T]: (item: T) => void; }[keyof T] +>callbacks : { [K in keyof T]: (item: T) => void; } +>key : keyof T +>item : T + } +} + diff --git a/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-index-signature-sibling-types-in-a-stable-order.js b/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-index-signature-sibling-types-in-a-stable-order.js index c2fc8d7b618c1..099a937e037bb 100644 --- a/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-index-signature-sibling-types-in-a-stable-order.js +++ b/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-index-signature-sibling-types-in-a-stable-order.js @@ -248,59 +248,61 @@ export declare const w: { {"id":82,"symbolName":"X","recursionId":76,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":25},"end":{"line":1,"character":26}},"flags":["TypeParameter"]}, {"id":83,"symbolName":"K","recursionId":77,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":34},"end":{"line":1,"character":46}},"flags":["TypeParameter"]}, {"id":84,"recursionId":78,"keyofType":82,"flags":["Index"]}, -{"id":85,"symbolName":"__type","recursionId":79,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, -{"id":86,"recursionId":76,"indexedAccessObjectType":82,"indexedAccessIndexType":83,"flags":["IndexedAccess"]}, -{"id":87,"symbolName":"Symbol","recursionId":80,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":18,"character":13},"end":{"line":18,"character":38}},"flags":["Object"]}, -{"id":88,"symbolName":"SymbolConstructor","recursionId":81,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":13,"character":1},"end":{"line":17,"character":2}},"flags":["Object"]}, -{"id":89,"symbolName":"toStringTag","recursionId":82,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":16,"character":5},"end":{"line":16,"character":34}},"flags":["UniqueESSymbol"]}, -{"id":90,"symbolName":"expand","recursionId":83,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":1},"end":{"line":1,"character":56}},"flags":["Object"],"display":"() => { [K in keyof X]: X[K]; }"}, -{"id":91,"symbolName":"C","recursionId":84,"instantiatedType":91,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["Object"]}, -{"id":92,"symbolName":"C","recursionId":84,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["TypeParameter"]}, -{"id":93,"symbolName":"__type","recursionId":84,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, -{"id":94,"symbolName":"K","recursionId":77,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":34},"end":{"line":1,"character":46}},"flags":["TypeParameter"]}, -{"id":95,"recursionId":85,"keyofType":91,"flags":["Index"]}, -{"id":96,"symbolName":"__type","recursionId":86,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":3,"character":11},"end":{"line":3,"character":19}},"flags":["Object"],"display":"{ a: 1; }"}, -{"id":97,"symbolName":"__type","recursionId":87,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":4,"character":9},"end":{"line":4,"character":18}},"flags":["Object"],"display":"{ p1: 1; }"}, -{"id":98,"symbolName":"__type","recursionId":88,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":5,"character":9},"end":{"line":5,"character":18}},"flags":["Object"],"display":"{ p2: 2; }"}, -{"id":99,"symbolName":"__type","recursionId":89,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":6,"character":9},"end":{"line":6,"character":18}},"flags":["Object"],"display":"{ p3: 3; }"}, -{"id":100,"symbolName":"__type","recursionId":90,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":7,"character":9},"end":{"line":7,"character":18}},"flags":["Object"],"display":"{ p4: 4; }"}, -{"id":101,"symbolName":"__type","recursionId":91,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":8,"character":9},"end":{"line":8,"character":18}},"flags":["Object"],"display":"{ p5: 5; }"}, -{"id":102,"symbolName":"__type","recursionId":92,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":9,"character":9},"end":{"line":9,"character":18}},"flags":["Object"],"display":"{ p6: 6; }"}, -{"id":103,"symbolName":"__type","recursionId":93,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":10,"character":9},"end":{"line":10,"character":18}},"flags":["Object"],"display":"{ p7: 7; }"}, -{"id":104,"symbolName":"__type","recursionId":94,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":11,"character":9},"end":{"line":11,"character":18}},"flags":["Object"],"display":"{ p8: 8; }"}, -{"id":105,"symbolName":"__type","recursionId":95,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":12,"character":9},"end":{"line":12,"character":18}},"flags":["Object"],"display":"{ p9: 9; }"}, -{"id":106,"symbolName":"__type","recursionId":96,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":13,"character":10},"end":{"line":13,"character":21}},"flags":["Object"],"display":"{ p10: 10; }"}, -{"id":107,"recursionId":97,"flags":["NumberLiteral"],"display":"10"}, -{"id":108,"recursionId":98,"flags":["NumberLiteral"],"display":"10"}, -{"id":109,"recursionId":99,"flags":["NumberLiteral"],"display":"9"}, -{"id":110,"recursionId":100,"flags":["NumberLiteral"],"display":"9"}, -{"id":111,"recursionId":101,"flags":["NumberLiteral"],"display":"8"}, -{"id":112,"recursionId":102,"flags":["NumberLiteral"],"display":"8"}, -{"id":113,"recursionId":103,"flags":["NumberLiteral"],"display":"7"}, -{"id":114,"recursionId":104,"flags":["NumberLiteral"],"display":"7"}, -{"id":115,"recursionId":105,"flags":["NumberLiteral"],"display":"6"}, -{"id":116,"recursionId":106,"flags":["NumberLiteral"],"display":"6"}, -{"id":117,"recursionId":107,"flags":["NumberLiteral"],"display":"5"}, -{"id":118,"recursionId":108,"flags":["NumberLiteral"],"display":"5"}, -{"id":119,"recursionId":109,"flags":["NumberLiteral"],"display":"4"}, -{"id":120,"recursionId":110,"flags":["NumberLiteral"],"display":"4"}, -{"id":121,"recursionId":111,"flags":["NumberLiteral"],"display":"3"}, -{"id":122,"recursionId":112,"flags":["NumberLiteral"],"display":"3"}, -{"id":123,"recursionId":113,"flags":["NumberLiteral"],"display":"2"}, -{"id":124,"recursionId":114,"flags":["NumberLiteral"],"display":"2"}, -{"id":125,"recursionId":115,"flags":["NumberLiteral"],"display":"1"}, -{"id":126,"recursionId":116,"flags":["NumberLiteral"],"display":"1"}, -{"id":127,"recursionId":117,"unionTypes":[96,97,98,99,100,101,102,103,104,105,106],"flags":["Union"],"display":"{ a: 1; } | { p1: 1; } | { p2: 2; } | { p3: 3; } | { p4: 4; } | { p5: 5; } | { p6: 6; } | { p7: 7; } | { p8: 8; } | { p9: 9; } | { p10: 10; }"}, -{"id":128,"recursionId":118,"flags":["StringLiteral"],"display":"\"m1\""}, -{"id":129,"recursionId":119,"flags":["StringLiteral"],"display":"\"m2\""}, -{"id":130,"recursionId":120,"flags":["StringLiteral"],"display":"\"m3\""}, -{"id":131,"recursionId":121,"flags":["StringLiteral"],"display":"\"m4\""}, -{"id":132,"recursionId":122,"flags":["StringLiteral"],"display":"\"m5\""}, -{"id":133,"recursionId":123,"flags":["StringLiteral"],"display":"\"m6\""}, -{"id":134,"recursionId":124,"flags":["StringLiteral"],"display":"\"m7\""}, -{"id":135,"recursionId":125,"flags":["StringLiteral"],"display":"\"m8\""}, -{"id":136,"recursionId":126,"flags":["StringLiteral"],"display":"\"m9\""}, -{"id":137,"recursionId":127,"flags":["StringLiteral"],"display":"\"m10\""}, -{"id":138,"recursionId":128,"unionTypes":[14,15],"flags":["Union"],"display":"keyof C"}] +{"id":85,"symbolName":"X","recursionId":76,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":25},"end":{"line":1,"character":26}},"flags":["TypeParameter"]}, +{"id":86,"symbolName":"__type","recursionId":79,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, +{"id":87,"recursionId":76,"indexedAccessObjectType":85,"indexedAccessIndexType":83,"flags":["IndexedAccess"]}, +{"id":88,"recursionId":80,"keyofType":85,"flags":["Index"]}, +{"id":89,"symbolName":"Symbol","recursionId":81,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":18,"character":13},"end":{"line":18,"character":38}},"flags":["Object"]}, +{"id":90,"symbolName":"SymbolConstructor","recursionId":82,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":13,"character":1},"end":{"line":17,"character":2}},"flags":["Object"]}, +{"id":91,"symbolName":"toStringTag","recursionId":83,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":16,"character":5},"end":{"line":16,"character":34}},"flags":["UniqueESSymbol"]}, +{"id":92,"symbolName":"expand","recursionId":84,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":1},"end":{"line":1,"character":56}},"flags":["Object"],"display":"() => { [K in keyof X]: X[K]; }"}, +{"id":93,"symbolName":"C","recursionId":85,"instantiatedType":93,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["Object"]}, +{"id":94,"symbolName":"C","recursionId":85,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["TypeParameter"]}, +{"id":95,"symbolName":"__type","recursionId":85,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, +{"id":96,"symbolName":"K","recursionId":77,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":34},"end":{"line":1,"character":46}},"flags":["TypeParameter"]}, +{"id":97,"recursionId":86,"keyofType":93,"flags":["Index"]}, +{"id":98,"symbolName":"__type","recursionId":87,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":3,"character":11},"end":{"line":3,"character":19}},"flags":["Object"],"display":"{ a: 1; }"}, +{"id":99,"symbolName":"__type","recursionId":88,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":4,"character":9},"end":{"line":4,"character":18}},"flags":["Object"],"display":"{ p1: 1; }"}, +{"id":100,"symbolName":"__type","recursionId":89,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":5,"character":9},"end":{"line":5,"character":18}},"flags":["Object"],"display":"{ p2: 2; }"}, +{"id":101,"symbolName":"__type","recursionId":90,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":6,"character":9},"end":{"line":6,"character":18}},"flags":["Object"],"display":"{ p3: 3; }"}, +{"id":102,"symbolName":"__type","recursionId":91,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":7,"character":9},"end":{"line":7,"character":18}},"flags":["Object"],"display":"{ p4: 4; }"}, +{"id":103,"symbolName":"__type","recursionId":92,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":8,"character":9},"end":{"line":8,"character":18}},"flags":["Object"],"display":"{ p5: 5; }"}, +{"id":104,"symbolName":"__type","recursionId":93,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":9,"character":9},"end":{"line":9,"character":18}},"flags":["Object"],"display":"{ p6: 6; }"}, +{"id":105,"symbolName":"__type","recursionId":94,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":10,"character":9},"end":{"line":10,"character":18}},"flags":["Object"],"display":"{ p7: 7; }"}, +{"id":106,"symbolName":"__type","recursionId":95,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":11,"character":9},"end":{"line":11,"character":18}},"flags":["Object"],"display":"{ p8: 8; }"}, +{"id":107,"symbolName":"__type","recursionId":96,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":12,"character":9},"end":{"line":12,"character":18}},"flags":["Object"],"display":"{ p9: 9; }"}, +{"id":108,"symbolName":"__type","recursionId":97,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":13,"character":10},"end":{"line":13,"character":21}},"flags":["Object"],"display":"{ p10: 10; }"}, +{"id":109,"recursionId":98,"flags":["NumberLiteral"],"display":"10"}, +{"id":110,"recursionId":99,"flags":["NumberLiteral"],"display":"10"}, +{"id":111,"recursionId":100,"flags":["NumberLiteral"],"display":"9"}, +{"id":112,"recursionId":101,"flags":["NumberLiteral"],"display":"9"}, +{"id":113,"recursionId":102,"flags":["NumberLiteral"],"display":"8"}, +{"id":114,"recursionId":103,"flags":["NumberLiteral"],"display":"8"}, +{"id":115,"recursionId":104,"flags":["NumberLiteral"],"display":"7"}, +{"id":116,"recursionId":105,"flags":["NumberLiteral"],"display":"7"}, +{"id":117,"recursionId":106,"flags":["NumberLiteral"],"display":"6"}, +{"id":118,"recursionId":107,"flags":["NumberLiteral"],"display":"6"}, +{"id":119,"recursionId":108,"flags":["NumberLiteral"],"display":"5"}, +{"id":120,"recursionId":109,"flags":["NumberLiteral"],"display":"5"}, +{"id":121,"recursionId":110,"flags":["NumberLiteral"],"display":"4"}, +{"id":122,"recursionId":111,"flags":["NumberLiteral"],"display":"4"}, +{"id":123,"recursionId":112,"flags":["NumberLiteral"],"display":"3"}, +{"id":124,"recursionId":113,"flags":["NumberLiteral"],"display":"3"}, +{"id":125,"recursionId":114,"flags":["NumberLiteral"],"display":"2"}, +{"id":126,"recursionId":115,"flags":["NumberLiteral"],"display":"2"}, +{"id":127,"recursionId":116,"flags":["NumberLiteral"],"display":"1"}, +{"id":128,"recursionId":117,"flags":["NumberLiteral"],"display":"1"}, +{"id":129,"recursionId":118,"unionTypes":[98,99,100,101,102,103,104,105,106,107,108],"flags":["Union"],"display":"{ a: 1; } | { p1: 1; } | { p2: 2; } | { p3: 3; } | { p4: 4; } | { p5: 5; } | { p6: 6; } | { p7: 7; } | { p8: 8; } | { p9: 9; } | { p10: 10; }"}, +{"id":130,"recursionId":119,"flags":["StringLiteral"],"display":"\"m1\""}, +{"id":131,"recursionId":120,"flags":["StringLiteral"],"display":"\"m2\""}, +{"id":132,"recursionId":121,"flags":["StringLiteral"],"display":"\"m3\""}, +{"id":133,"recursionId":122,"flags":["StringLiteral"],"display":"\"m4\""}, +{"id":134,"recursionId":123,"flags":["StringLiteral"],"display":"\"m5\""}, +{"id":135,"recursionId":124,"flags":["StringLiteral"],"display":"\"m6\""}, +{"id":136,"recursionId":125,"flags":["StringLiteral"],"display":"\"m7\""}, +{"id":137,"recursionId":126,"flags":["StringLiteral"],"display":"\"m8\""}, +{"id":138,"recursionId":127,"flags":["StringLiteral"],"display":"\"m9\""}, +{"id":139,"recursionId":128,"flags":["StringLiteral"],"display":"\"m10\""}, +{"id":140,"recursionId":129,"unionTypes":[14,15],"flags":["Union"],"display":"keyof C"}] diff --git a/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-static-index-signature-sibling-types-in-a-stable-order.js b/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-static-index-signature-sibling-types-in-a-stable-order.js index 91ed1755c8ff3..e0a6e05e5aa65 100644 --- a/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-static-index-signature-sibling-types-in-a-stable-order.js +++ b/tsc/testdata/baselines/reference/tsc/generateTrace/generateTrace-creates-static-index-signature-sibling-types-in-a-stable-order.js @@ -227,58 +227,60 @@ export declare const w: { {"id":82,"symbolName":"X","recursionId":76,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":25},"end":{"line":1,"character":26}},"flags":["TypeParameter"]}, {"id":83,"symbolName":"K","recursionId":77,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":34},"end":{"line":1,"character":46}},"flags":["TypeParameter"]}, {"id":84,"recursionId":78,"keyofType":82,"flags":["Index"]}, -{"id":85,"symbolName":"__type","recursionId":79,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, -{"id":86,"recursionId":76,"indexedAccessObjectType":82,"indexedAccessIndexType":83,"flags":["IndexedAccess"]}, -{"id":87,"symbolName":"Symbol","recursionId":80,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":18,"character":13},"end":{"line":18,"character":38}},"flags":["Object"]}, -{"id":88,"symbolName":"SymbolConstructor","recursionId":81,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":13,"character":1},"end":{"line":17,"character":2}},"flags":["Object"]}, -{"id":89,"symbolName":"toStringTag","recursionId":82,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":16,"character":5},"end":{"line":16,"character":34}},"flags":["UniqueESSymbol"]}, -{"id":90,"symbolName":"expand","recursionId":83,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":1},"end":{"line":1,"character":56}},"flags":["Object"],"display":"() => { [K in keyof X]: X[K]; }"}, -{"id":91,"symbolName":"C","recursionId":84,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["Object"],"display":"typeof C"}, -{"id":92,"symbolName":"C","recursionId":85,"instantiatedType":92,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["Object"]}, -{"id":93,"symbolName":"C","recursionId":85,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["TypeParameter"]}, -{"id":94,"symbolName":"__type","recursionId":84,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, -{"id":95,"symbolName":"K","recursionId":77,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":34},"end":{"line":1,"character":46}},"flags":["TypeParameter"]}, -{"id":96,"symbolName":"__type","recursionId":86,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":3,"character":18},"end":{"line":3,"character":26}},"flags":["Object"],"display":"{ a: 1; }"}, -{"id":97,"symbolName":"__type","recursionId":87,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":4,"character":16},"end":{"line":4,"character":25}},"flags":["Object"],"display":"{ p1: 1; }"}, -{"id":98,"symbolName":"__type","recursionId":88,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":5,"character":16},"end":{"line":5,"character":25}},"flags":["Object"],"display":"{ p2: 2; }"}, -{"id":99,"symbolName":"__type","recursionId":89,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":6,"character":16},"end":{"line":6,"character":25}},"flags":["Object"],"display":"{ p3: 3; }"}, -{"id":100,"symbolName":"__type","recursionId":90,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":7,"character":16},"end":{"line":7,"character":25}},"flags":["Object"],"display":"{ p4: 4; }"}, -{"id":101,"symbolName":"__type","recursionId":91,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":8,"character":16},"end":{"line":8,"character":25}},"flags":["Object"],"display":"{ p5: 5; }"}, -{"id":102,"symbolName":"__type","recursionId":92,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":9,"character":16},"end":{"line":9,"character":25}},"flags":["Object"],"display":"{ p6: 6; }"}, -{"id":103,"symbolName":"__type","recursionId":93,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":10,"character":16},"end":{"line":10,"character":25}},"flags":["Object"],"display":"{ p7: 7; }"}, -{"id":104,"symbolName":"__type","recursionId":94,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":11,"character":16},"end":{"line":11,"character":25}},"flags":["Object"],"display":"{ p8: 8; }"}, -{"id":105,"symbolName":"__type","recursionId":95,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":12,"character":16},"end":{"line":12,"character":25}},"flags":["Object"],"display":"{ p9: 9; }"}, -{"id":106,"symbolName":"__type","recursionId":96,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":13,"character":17},"end":{"line":13,"character":28}},"flags":["Object"],"display":"{ p10: 10; }"}, -{"id":107,"recursionId":97,"flags":["NumberLiteral"],"display":"10"}, -{"id":108,"recursionId":98,"flags":["NumberLiteral"],"display":"10"}, -{"id":109,"recursionId":99,"flags":["NumberLiteral"],"display":"9"}, -{"id":110,"recursionId":100,"flags":["NumberLiteral"],"display":"9"}, -{"id":111,"recursionId":101,"flags":["NumberLiteral"],"display":"8"}, -{"id":112,"recursionId":102,"flags":["NumberLiteral"],"display":"8"}, -{"id":113,"recursionId":103,"flags":["NumberLiteral"],"display":"7"}, -{"id":114,"recursionId":104,"flags":["NumberLiteral"],"display":"7"}, -{"id":115,"recursionId":105,"flags":["NumberLiteral"],"display":"6"}, -{"id":116,"recursionId":106,"flags":["NumberLiteral"],"display":"6"}, -{"id":117,"recursionId":107,"flags":["NumberLiteral"],"display":"5"}, -{"id":118,"recursionId":108,"flags":["NumberLiteral"],"display":"5"}, -{"id":119,"recursionId":109,"flags":["NumberLiteral"],"display":"4"}, -{"id":120,"recursionId":110,"flags":["NumberLiteral"],"display":"4"}, -{"id":121,"recursionId":111,"flags":["NumberLiteral"],"display":"3"}, -{"id":122,"recursionId":112,"flags":["NumberLiteral"],"display":"3"}, -{"id":123,"recursionId":113,"flags":["NumberLiteral"],"display":"2"}, -{"id":124,"recursionId":114,"flags":["NumberLiteral"],"display":"2"}, -{"id":125,"recursionId":115,"flags":["NumberLiteral"],"display":"1"}, -{"id":126,"recursionId":116,"flags":["NumberLiteral"],"display":"1"}, -{"id":127,"recursionId":117,"flags":["StringLiteral"],"display":"\"m1\""}, -{"id":128,"recursionId":118,"flags":["StringLiteral"],"display":"\"m2\""}, -{"id":129,"recursionId":119,"flags":["StringLiteral"],"display":"\"m3\""}, -{"id":130,"recursionId":120,"flags":["StringLiteral"],"display":"\"m4\""}, -{"id":131,"recursionId":121,"flags":["StringLiteral"],"display":"\"m5\""}, -{"id":132,"recursionId":122,"flags":["StringLiteral"],"display":"\"m6\""}, -{"id":133,"recursionId":123,"flags":["StringLiteral"],"display":"\"m7\""}, -{"id":134,"recursionId":124,"flags":["StringLiteral"],"display":"\"m8\""}, -{"id":135,"recursionId":125,"flags":["StringLiteral"],"display":"\"m9\""}, -{"id":136,"recursionId":126,"flags":["StringLiteral"],"display":"\"m10\""}, -{"id":137,"recursionId":127,"flags":["StringLiteral"],"display":"\"prototype\""}] +{"id":85,"symbolName":"X","recursionId":76,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":25},"end":{"line":1,"character":26}},"flags":["TypeParameter"]}, +{"id":86,"symbolName":"__type","recursionId":79,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, +{"id":87,"recursionId":76,"indexedAccessObjectType":85,"indexedAccessIndexType":83,"flags":["IndexedAccess"]}, +{"id":88,"recursionId":80,"keyofType":85,"flags":["Index"]}, +{"id":89,"symbolName":"Symbol","recursionId":81,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":18,"character":13},"end":{"line":18,"character":38}},"flags":["Object"]}, +{"id":90,"symbolName":"SymbolConstructor","recursionId":82,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":13,"character":1},"end":{"line":17,"character":2}},"flags":["Object"]}, +{"id":91,"symbolName":"toStringTag","recursionId":83,"firstDeclaration":{"path":"/home/src/tslibs/ts/lib/lib.es2026.full.d.ts","start":{"line":16,"character":5},"end":{"line":16,"character":34}},"flags":["UniqueESSymbol"]}, +{"id":92,"symbolName":"expand","recursionId":84,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":1},"end":{"line":1,"character":56}},"flags":["Object"],"display":"() => { [K in keyof X]: X[K]; }"}, +{"id":93,"symbolName":"C","recursionId":85,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["Object"],"display":"typeof C"}, +{"id":94,"symbolName":"C","recursionId":86,"instantiatedType":94,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["Object"]}, +{"id":95,"symbolName":"C","recursionId":86,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":2,"character":1},"end":{"line":14,"character":2}},"flags":["TypeParameter"]}, +{"id":96,"symbolName":"__type","recursionId":85,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":31},"end":{"line":1,"character":55}},"flags":["Object"]}, +{"id":97,"symbolName":"K","recursionId":77,"firstDeclaration":{"path":"/home/src/workspaces/project/main.ts","start":{"line":1,"character":34},"end":{"line":1,"character":46}},"flags":["TypeParameter"]}, +{"id":98,"symbolName":"__type","recursionId":87,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":3,"character":18},"end":{"line":3,"character":26}},"flags":["Object"],"display":"{ a: 1; }"}, +{"id":99,"symbolName":"__type","recursionId":88,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":4,"character":16},"end":{"line":4,"character":25}},"flags":["Object"],"display":"{ p1: 1; }"}, +{"id":100,"symbolName":"__type","recursionId":89,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":5,"character":16},"end":{"line":5,"character":25}},"flags":["Object"],"display":"{ p2: 2; }"}, +{"id":101,"symbolName":"__type","recursionId":90,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":6,"character":16},"end":{"line":6,"character":25}},"flags":["Object"],"display":"{ p3: 3; }"}, +{"id":102,"symbolName":"__type","recursionId":91,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":7,"character":16},"end":{"line":7,"character":25}},"flags":["Object"],"display":"{ p4: 4; }"}, +{"id":103,"symbolName":"__type","recursionId":92,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":8,"character":16},"end":{"line":8,"character":25}},"flags":["Object"],"display":"{ p5: 5; }"}, +{"id":104,"symbolName":"__type","recursionId":93,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":9,"character":16},"end":{"line":9,"character":25}},"flags":["Object"],"display":"{ p6: 6; }"}, +{"id":105,"symbolName":"__type","recursionId":94,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":10,"character":16},"end":{"line":10,"character":25}},"flags":["Object"],"display":"{ p7: 7; }"}, +{"id":106,"symbolName":"__type","recursionId":95,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":11,"character":16},"end":{"line":11,"character":25}},"flags":["Object"],"display":"{ p8: 8; }"}, +{"id":107,"symbolName":"__type","recursionId":96,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":12,"character":16},"end":{"line":12,"character":25}},"flags":["Object"],"display":"{ p9: 9; }"}, +{"id":108,"symbolName":"__type","recursionId":97,"firstDeclaration":{"path":"/home/src/workspaces/project/ambient.d.ts","start":{"line":13,"character":17},"end":{"line":13,"character":28}},"flags":["Object"],"display":"{ p10: 10; }"}, +{"id":109,"recursionId":98,"flags":["NumberLiteral"],"display":"10"}, +{"id":110,"recursionId":99,"flags":["NumberLiteral"],"display":"10"}, +{"id":111,"recursionId":100,"flags":["NumberLiteral"],"display":"9"}, +{"id":112,"recursionId":101,"flags":["NumberLiteral"],"display":"9"}, +{"id":113,"recursionId":102,"flags":["NumberLiteral"],"display":"8"}, +{"id":114,"recursionId":103,"flags":["NumberLiteral"],"display":"8"}, +{"id":115,"recursionId":104,"flags":["NumberLiteral"],"display":"7"}, +{"id":116,"recursionId":105,"flags":["NumberLiteral"],"display":"7"}, +{"id":117,"recursionId":106,"flags":["NumberLiteral"],"display":"6"}, +{"id":118,"recursionId":107,"flags":["NumberLiteral"],"display":"6"}, +{"id":119,"recursionId":108,"flags":["NumberLiteral"],"display":"5"}, +{"id":120,"recursionId":109,"flags":["NumberLiteral"],"display":"5"}, +{"id":121,"recursionId":110,"flags":["NumberLiteral"],"display":"4"}, +{"id":122,"recursionId":111,"flags":["NumberLiteral"],"display":"4"}, +{"id":123,"recursionId":112,"flags":["NumberLiteral"],"display":"3"}, +{"id":124,"recursionId":113,"flags":["NumberLiteral"],"display":"3"}, +{"id":125,"recursionId":114,"flags":["NumberLiteral"],"display":"2"}, +{"id":126,"recursionId":115,"flags":["NumberLiteral"],"display":"2"}, +{"id":127,"recursionId":116,"flags":["NumberLiteral"],"display":"1"}, +{"id":128,"recursionId":117,"flags":["NumberLiteral"],"display":"1"}, +{"id":129,"recursionId":118,"flags":["StringLiteral"],"display":"\"m1\""}, +{"id":130,"recursionId":119,"flags":["StringLiteral"],"display":"\"m2\""}, +{"id":131,"recursionId":120,"flags":["StringLiteral"],"display":"\"m3\""}, +{"id":132,"recursionId":121,"flags":["StringLiteral"],"display":"\"m4\""}, +{"id":133,"recursionId":122,"flags":["StringLiteral"],"display":"\"m5\""}, +{"id":134,"recursionId":123,"flags":["StringLiteral"],"display":"\"m6\""}, +{"id":135,"recursionId":124,"flags":["StringLiteral"],"display":"\"m7\""}, +{"id":136,"recursionId":125,"flags":["StringLiteral"],"display":"\"m8\""}, +{"id":137,"recursionId":126,"flags":["StringLiteral"],"display":"\"m9\""}, +{"id":138,"recursionId":127,"flags":["StringLiteral"],"display":"\"m10\""}, +{"id":139,"recursionId":128,"flags":["StringLiteral"],"display":"\"prototype\""}] diff --git a/tsc/testdata/tests/cases/compiler/distributedMappedTypeIndexSignature.ts b/tsc/testdata/tests/cases/compiler/distributedMappedTypeIndexSignature.ts new file mode 100644 index 0000000000000..2b3fb9946b42c --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/distributedMappedTypeIndexSignature.ts @@ -0,0 +1,12 @@ +// @strict: true +// @noEmit: true + +type Alias = { [K in keyof T]: (state: T) => void }; +type Check void }> = X; +type Use1 = Check>; +type Use2 = Check void }>; + +function f(alias: Alias, inline: { [K in keyof T]: (state: T) => T[K] }) { + const a: Record unknown> = alias; + const b: Record unknown> = inline; +} diff --git a/tsc/testdata/tests/cases/compiler/distributedTypeParameters.ts b/tsc/testdata/tests/cases/compiler/distributedTypeParameters.ts index cb0eedf5dc15a..6020ecf572bbd 100644 --- a/tsc/testdata/tests/cases/compiler/distributedTypeParameters.ts +++ b/tsc/testdata/tests/cases/compiler/distributedTypeParameters.ts @@ -64,6 +64,40 @@ type T5 = Show : never; +type M1 = { + [K in keyof A]: Show; // Error +}; + +type M2 = { + [K in keyof A as K]: Show; // Error +}; + +type M3 = { + [K in keyof A & string]: Show; +}; + +type X5 = M1<{ a: 0 } | { b: 1 }, { a: 0 }>; +type X6 = M2<{ a: 0 } | { b: 1 }, { a: 0 }>; + +type ShowResult = U extends T ? true : false; + +declare function conditionalIndexedAccess(y: U): + T extends unknown ? ShowResult : never; // Error + +const conditionalIndexedAccessResult = conditionalIndexedAccess< + { a: 1 } | { b: 2 }, + { a: 1 } +>({ a: 1 }); + +declare function mappedIndexedAccess(y: U): { + [P in keyof T]: ShowResult; // Error +}; + +const mappedIndexedAccessResult = mappedIndexedAccess< + { a: 1 } | { b: 2 }, + { a: 1 } +>({ a: 1 }); + // Ensure mapped type modifiers are computed correctly, example from type-fest type IsReadonlyKeyOf = @@ -94,3 +128,39 @@ type _IsEqual = type T10 = IsReadonlyKeyOf<{ a: string }, 'a'>; // false type T11 = IsReadonlyKeyOf<{ readonly b: string }, 'b'>; // true + +// Repro from triggerdotdev/trigger.dev + +type Exact = + P extends unknown ? + { [K in keyof P]: Exact } : // Error + never; + +type X7 = Exact<{ a: 0 } | { b: 1 }, { a: 0 }>; + +// Homomorphic mapped types instantiated for a distributed type parameter keep its distributed form + +type Mutable = { -readonly [K in keyof T]: T[K] }; + +type C1 = T extends unknown ? Show, U> : never; // Error +type C2 = T extends unknown ? Show, U> : never; // Error +type C3 = T extends unknown ? Show, Mutable> : never; // Error +type C4 = T extends unknown ? Show<{ [K in keyof T]: T[K] }, U> : never; // Error +type M4 = { [K in keyof T]: Show, U> }; // Error + +// Normalization doesn't depend on whether the template was resolved before + +declare function inferFromMappedGetter(u: { [K in keyof U]: () => U }): () => U; + +function f1(getter: () => T) { + let r = inferFromMappedGetter(get()); + r = getter; + function get(): { [K in keyof T]: () => T } { return null!; } +} + +type M5 = { [K in keyof A]: { [J in keyof B]: Show } }; +type M6 = { [K in keyof B]: { [J in keyof A]: Show } }; +type M7 = { [K in keyof A]: Show }; +type M8 = { [K in keyof A]: { [J in keyof B]: [Show, Show] } }; +type M9 = { [K in keyof A as Show extends never ? never : K]: 0 }; +type M10 = { [K in keyof [A]]: Show }; diff --git a/tsc/testdata/tests/cases/compiler/distributedTypeParametersParenthesized.ts b/tsc/testdata/tests/cases/compiler/distributedTypeParametersParenthesized.ts new file mode 100644 index 0000000000000..cd9fdf274c1d2 --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/distributedTypeParametersParenthesized.ts @@ -0,0 +1,13 @@ +// @strict: true +// @noEmit: true + +type Show = B extends A ? true : false; + +type Conditional1 = T extends unknown ? Show : never; +type Conditional2 = (T) extends unknown ? Show : never; +type Conditional3 = ((T)) extends unknown ? Show : never; + +type Mapped1 = { [K in keyof T]: Show }; +type Mapped2 = { [K in keyof (T)]: Show }; +type Mapped3 = { [K in (keyof T)]: Show }; +type Mapped4 = { [K in ((keyof (T)))]: Show }; diff --git a/tsc/testdata/tests/cases/compiler/reverseMappedTypeNestedInference.ts b/tsc/testdata/tests/cases/compiler/reverseMappedTypeNestedInference.ts new file mode 100644 index 0000000000000..bd535242e040d --- /dev/null +++ b/tsc/testdata/tests/cases/compiler/reverseMappedTypeNestedInference.ts @@ -0,0 +1,23 @@ +// @strict: true +// @declaration: true + +declare const sv: (input: unknown) => string | undefined; + +declare function d3(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: (i: unknown) => T[K][J][L] } } }): T; +export const r3 = d3({ a: { b: { c: sv } } }); + +declare function d4(input: { [K in keyof T]: { [J in keyof T[K]]: { [L in keyof T[K][J]]: { [M in keyof T[K][J][L]]: (i: unknown) => T[K][J][L][M] } } } }): T; +export const r4 = d4({ a: { b: { c: { d: sv } } } }); + +type Deep2 = { [K in keyof T]: { [J in keyof T[K]]: Deep2 | ((i: unknown) => T[K][J]) } }; +declare function dd(input: Deep2): T; +export const rd = dd({ a: { b: { c: { d: sv } } } }); + +declare function dk(input: { [K in keyof T]: { [J in keyof T[K]]: (i: unknown) => T[K][J] } }, k: U): T[U]; +export const rk = dk({ a: { b: sv } }, "a"); + +declare function revTuple(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +export const rt = revTuple([{ a: () => 1 }, { b: () => "s" }] as const); + +declare function revTupleUnconstrained(x: { [K in keyof V]: { [J in keyof V[K]]: () => V[K][J] } }): V; +export const rtu = revTupleUnconstrained([{ a: () => 1 }, { b: () => "s" }] as const); diff --git a/tsc/testdata/tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts b/tsc/testdata/tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts index b6a5ba7f0cfba..84137f7410345 100644 --- a/tsc/testdata/tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts +++ b/tsc/testdata/tests/cases/conformance/types/mapped/isomorphicMappedTypeInference.ts @@ -181,3 +181,80 @@ const myAny: any = {}; const o1 = getProps(myAny, ['foo', 'bar']); const o2: { foo: any; bar: any } = getProps(myAny, ['foo', 'bar']); + +// Inference between homomorphic mapped types should infer the original type +// parameter, not its distributed representation. +declare function inferFromMapped(value: { [P in keyof T]: T[P] }): T; + +function f30(value: { [P in keyof U]: U[P] }, ordinary: U) { + const inferred = inferFromMapped(value); + const accept: typeof inferred = ordinary; +} + +// Inference to homomorphic mapped types nested in conditional types + +declare function inferInNonDistributive(x: [T] extends [object] ? { [K in keyof T]: () => T[K] } : never): T; +const inferredInNonDistributive = inferInNonDistributive({ a: () => 1 }); + +declare function inferInDistributive(x: T extends unknown ? { [K in keyof T]: () => T[K] } : never): T; +const inferredInDistributive = inferInDistributive({ a: () => 1 }); + +declare function inferFromMappedSelf(value: { [P in keyof T]: T }): T; +function f40(value: { [P in keyof U]: U }, ordinary: U) { + const inferred = inferFromMappedSelf(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedBox(value: { [P in keyof X]: Box }): T; +function f41(value: { [P in keyof U]: Box }, ordinary: U) { + const inferred = inferFromMappedBox(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedInlineObject(value: { [P in keyof X]: { value: T } }): T; +function f42(value: { [P in keyof U]: { value: U } }, ordinary: U) { + const inferred = inferFromMappedInlineObject(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedInlineFunction(value: { [P in keyof X]: (arg: T) => T }): T; +function f43(value: { [P in keyof U]: (arg: U) => U }, ordinary: U) { + const inferred = inferFromMappedInlineFunction(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedInlineIntersection(value: { [P in keyof X]: { a: T } & { b: T } }): T; +function f44(value: { [P in keyof U]: { a: U } & { b: U } }, ordinary: U) { + const inferred = inferFromMappedInlineIntersection(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedConditional(value: { [P in keyof X]: X[P] extends string ? { value: T } : never }): T; +function f45(value: { [P in keyof U]: U[P] extends string ? { value: U } : never }, ordinary: U) { + const inferred = inferFromMappedConditional(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromPlainTargetOfMapped(value: { a: { value: T } }): T; +function f46(value: { [P in keyof U]: { value: U } }, ordinary: U) { + const inferred = inferFromPlainTargetOfMapped(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromWrappedMapped(value: { wrap: { [P in keyof X]: { value: T } } }): T; +function f47(value: { wrap: { [P in keyof U]: { value: U } } }, ordinary: U) { + const inferred = inferFromWrappedMapped(value); + const accept: typeof inferred = ordinary; +} + +declare function inferFromMappedCallbackParameter(cb: (arg: { [P in keyof X]: { value: T } }) => void): T; +function f48(cb: (arg: { [P in keyof U]: { value: U } }) => void, ordinary: U) { + const inferred = inferFromMappedCallbackParameter(cb); + const accept: typeof inferred = ordinary; +} + +declare function inferFromDeeplyNestedMapped(value: { [P in keyof X]: { a: { b: [() => T] } } }): T; +function f49(value: { [P in keyof U]: { a: { b: [() => U] } } }, ordinary: U) { + const inferred = inferFromDeeplyNestedMapped(value); + const accept: typeof inferred = ordinary; +} diff --git a/tsc/testdata/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts b/tsc/testdata/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts index ba9bef645fedb..1b3cd80e5f0c9 100644 --- a/tsc/testdata/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts +++ b/tsc/testdata/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts @@ -210,4 +210,82 @@ type ConcreteSettingsResult1 = Settings; type ConcreteSettingsResult2 = Settings; type GenericSettingsAccess = Settings; type GenericSettingsResult1 = GenericSettingsAccess<"audio">; -type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; \ No newline at end of file +type GenericSettingsResult2 = GenericSettingsAccess<"audio" | "video">; +function mappedRelations1(x: { [K in keyof T]: [T, T[K]] }, y: { [K in keyof T]: [T, T[K]] }) { + x = y; + y = x; +} + +function mappedRelations2(x: { [K in keyof T]: { t: T, k: T[K] } }, y: { [K in keyof T]: { t: T, k: T[K] } }) { + x = y; + y = x; +} + +function mappedRelations3(x: { [K in keyof T]: (t: T) => T[K] }, y: { [K in keyof T]: (t: T) => T[K] }) { + x = y; + y = x; +} + +function mappedRelations4( + x: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, + y: { [K in keyof T]: T[K] extends string ? { t: T } : { u: T } }, +) { + x = y; + y = x; +} + +function mappedRelations5(x: { [K in keyof T]: { t: T } }) { + const make = (v: V): { [K in keyof T]: { t: T, v: V } } => null!; + x = make(1); +} + +function mappedRelations6(x: T extends object ? { inner: { [K in keyof T]: T } } : never, y: { [K in keyof T]: T }) { + x.inner = y; + y = x.inner; +} + +interface MappedBox { value: X } +function mappedRelations7(x: MappedBox<{ [K in keyof T]: { t: T } }>, y: MappedBox<{ [K in keyof T]: { t: T } }>) { + x = y; + y = x; +} + +type MappedAlias = { [K in keyof T]: { t: T, k: T[K] } }; +type MappedRecursive = { [K in keyof T]: { next: MappedRecursive, t: T } }; +function mappedRelations8(x: MappedAlias, y: { [K in keyof T]: { t: T, k: T[K] } }) { + x = y; + y = x; + const make = (v: V): MappedAlias => null!; + x = make(1); +} + +function mappedRelations9(x: MappedRecursive, y: { [K in keyof T]: { next: MappedRecursive, t: T } }) { + x = y; + y = x; +} + +function mappedRelations10(x: { [K in keyof T]: T }, y: T, z: { [K in keyof T]: U }) { + x = y; + x = z; + z = x; +} + +declare let mappedSignature1: (m: A, r: (a: { [K in keyof A]: A }) => void) => void; +let mappedSignature2: (m: A, r: (a: { [K in keyof A]: A }) => void) => void = mappedSignature1; + +type MappedSigA = { m(u: U): void }; +type MappedSigB = { m(u: U): void }; +declare const mappedSigs: MappedSigA | MappedSigB; +mappedSigs.m({}); + +function mappedRelations11() { + type M = { [K in keyof X]: X }; + var a: { [K in keyof T]: T }; + var a: M; +} + +class MappedCallbacks { + m(item: T, callbacks: { [K in keyof T]: (item: T) => void }, key: keyof T): void { + callbacks[key](item); + } +}