diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d4f288f1293b..a7097b50a42e1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2038,6 +2038,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var unknownEmptyObjectType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray); var unknownUnionType = strictNullChecks ? getUnionType([undefinedType, nullType, unknownEmptyObjectType]) : unknownType; + var keyofConstraintObjectType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, [stringType, numberType, esSymbolType].map(t => createIndexInfo(t, unknownType, /*isReadonly*/ false))); // { [k: string | number | symbol]: unknown; } + var emptyGenericType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray) as ObjectType as GenericType; emptyGenericType.instantiations = new Map(); @@ -13667,21 +13669,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return instantiateType(instantiable, createTypeMapper([type.indexType, type.objectType], [getNumberLiteralType(0), createTupleType([replacement])])); } - // If the original mapped type had an intersection constraint we extract its components, - // and we make an attempt to do so even if the intersection has been reduced to a union. - // This entire process allows us to possibly retrieve the filtering type literals. - // e.g. { [K in keyof U & ("a" | "b") ] } -> "a" | "b" - function getLimitedConstraint(type: ReverseMappedType) { + // If the original mapped type had an union/intersection constraint + // there is a chance that it includes an intersection that could limit what members are allowed + function getReverseMappedTypeMembersLimitingConstraint(type: ReverseMappedType) { const constraint = getConstraintTypeFromMappedType(type.mappedType); - if (!(constraint.flags & TypeFlags.Union || constraint.flags & TypeFlags.Intersection)) { - return; - } - const origin = (constraint.flags & TypeFlags.Union) ? (constraint as UnionType).origin : (constraint as IntersectionType); - if (!origin || !(origin.flags & TypeFlags.Intersection)) { + if (constraint === type.constraintType) { return; } - const limitedConstraint = getIntersectionType((origin as IntersectionType).types.filter(t => t !== type.constraintType)); - return limitedConstraint !== neverType ? limitedConstraint : undefined; + const mapper = appendTypeMapping(type.mappedType.mapper, type.constraintType.type, getIntersectionType([type.constraintType.type, keyofConstraintObjectType])); + return getBaseConstraintOrType(instantiateType(constraint, mapper)); } function resolveReverseMappedTypeMembers(type: ReverseMappedType) { @@ -13691,14 +13687,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const optionalMask = modifiers & MappedTypeModifiers.IncludeOptional ? 0 : SymbolFlags.Optional; const indexInfos = indexInfo ? [createIndexInfo(stringType, inferReverseMappedType(indexInfo.type, type.mappedType, type.constraintType), readonlyMask && indexInfo.isReadonly)] : emptyArray; const members = createSymbolTable(); - const limitedConstraint = getLimitedConstraint(type); + const membersLimitingConstraint = getReverseMappedTypeMembersLimitingConstraint(type); for (const prop of getPropertiesOfType(type.source)) { - // In case of a reverse mapped type with an intersection constraint, if we were able to - // extract the filtering type literals we skip those properties that are not assignable to them, - // because the extra properties wouldn't get through the application of the mapped type anyway - if (limitedConstraint) { + // we skip those properties that are not assignable to the limiting constraint + // the extra properties wouldn't get through the application of the mapped type anyway + // and their inferred type might not satisfy the type parameter's constraint + // which, in turn, could fail the check if the inferred type is assignable to its constraint + // + // inferring `{ a: number; b: string }` wouldn't satisfy T's constraint so b has to be skipped here + // + // declare function fn>(arg: { [K in keyof T & "a"]: T[K] }): T + // const obj = { a: 1, b: '2' }; + // fn(obj); + if (membersLimitingConstraint) { const propertyNameType = getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique); - if (!isTypeAssignableTo(propertyNameType, limitedConstraint)) { + if (!isTypeAssignableTo(propertyNameType, membersLimitingConstraint)) { continue; } } @@ -25749,9 +25752,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function inferToMappedType(source: Type, target: MappedType, constraintType: Type): boolean { - if ((constraintType.flags & TypeFlags.Union) || (constraintType.flags & TypeFlags.Intersection)) { + if (constraintType.flags & TypeFlags.UnionOrIntersection) { let result = false; - for (const type of (constraintType as (UnionType | IntersectionType)).types) { + for (const type of (constraintType as UnionOrIntersectionType).types) { result = inferToMappedType(source, target, type) || result; } return result; diff --git a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.symbols b/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.symbols deleted file mode 100644 index 12cb8664c8409..0000000000000 --- a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.symbols +++ /dev/null @@ -1,491 +0,0 @@ -//// [tests/cases/compiler/reverseMappedTypeIntersectionConstraint.ts] //// - -=== reverseMappedTypeIntersectionConstraint.ts === -type StateConfig = { ->StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 0)) ->TAction : Symbol(TAction, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 17)) - - entry?: TAction ->entry : Symbol(entry, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 44)) ->TAction : Symbol(TAction, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 17)) - - states?: Record>; ->states : Symbol(states, Decl(reverseMappedTypeIntersectionConstraint.ts, 1, 17)) ->Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 0)) ->TAction : Symbol(TAction, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 17)) - -}; - -type StateSchema = { ->StateSchema : Symbol(StateSchema, Decl(reverseMappedTypeIntersectionConstraint.ts, 3, 2)) - - states?: Record; ->states : Symbol(states, Decl(reverseMappedTypeIntersectionConstraint.ts, 5, 20)) ->Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->StateSchema : Symbol(StateSchema, Decl(reverseMappedTypeIntersectionConstraint.ts, 3, 2)) - -}; - -declare function createMachine< ->createMachine : Symbol(createMachine, Decl(reverseMappedTypeIntersectionConstraint.ts, 7, 2)) - - TConfig extends StateConfig, ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 9, 31)) ->StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 0)) ->TAction : Symbol(TAction, Decl(reverseMappedTypeIntersectionConstraint.ts, 10, 39)) - - TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string, ->TAction : Symbol(TAction, Decl(reverseMappedTypeIntersectionConstraint.ts, 10, 39)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 9, 31)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 9, 31)) - ->(config: { [K in keyof TConfig & keyof StateConfig]: TConfig[K] }): [TAction, TConfig]; ->config : Symbol(config, Decl(reverseMappedTypeIntersectionConstraint.ts, 12, 2)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 12, 13)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 9, 31)) ->StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 0, 0)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 9, 31)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 12, 13)) ->TAction : Symbol(TAction, Decl(reverseMappedTypeIntersectionConstraint.ts, 10, 39)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 9, 31)) - -const inferredParams1 = createMachine({ ->inferredParams1 : Symbol(inferredParams1, Decl(reverseMappedTypeIntersectionConstraint.ts, 14, 5)) ->createMachine : Symbol(createMachine, Decl(reverseMappedTypeIntersectionConstraint.ts, 7, 2)) - - entry: "foo", ->entry : Symbol(entry, Decl(reverseMappedTypeIntersectionConstraint.ts, 14, 39)) - - states: { ->states : Symbol(states, Decl(reverseMappedTypeIntersectionConstraint.ts, 15, 15)) - - a: { ->a : Symbol(a, Decl(reverseMappedTypeIntersectionConstraint.ts, 16, 11)) - - entry: "bar", ->entry : Symbol(entry, Decl(reverseMappedTypeIntersectionConstraint.ts, 17, 8)) - - }, - }, - extra: 12, ->extra : Symbol(extra, Decl(reverseMappedTypeIntersectionConstraint.ts, 20, 4)) - -}); - -const inferredParams2 = createMachine({ ->inferredParams2 : Symbol(inferredParams2, Decl(reverseMappedTypeIntersectionConstraint.ts, 24, 5)) ->createMachine : Symbol(createMachine, Decl(reverseMappedTypeIntersectionConstraint.ts, 7, 2)) - - entry: "foo", ->entry : Symbol(entry, Decl(reverseMappedTypeIntersectionConstraint.ts, 24, 39)) - - states: { ->states : Symbol(states, Decl(reverseMappedTypeIntersectionConstraint.ts, 25, 15)) - - a: { ->a : Symbol(a, Decl(reverseMappedTypeIntersectionConstraint.ts, 26, 11)) - - entry: "foo", ->entry : Symbol(entry, Decl(reverseMappedTypeIntersectionConstraint.ts, 27, 8)) - - }, - }, - extra: 12, ->extra : Symbol(extra, Decl(reverseMappedTypeIntersectionConstraint.ts, 30, 4)) - -}); - - -// ----------------------------------------------------------------------------------------- - -const checkType = () => (value: { [K in keyof U & keyof T]: U[K] }) => value; ->checkType : Symbol(checkType, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 5)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 19)) ->U : Symbol(U, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 28)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 19)) ->value : Symbol(value, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 41)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 51)) ->U : Symbol(U, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 28)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 19)) ->U : Symbol(U, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 28)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 51)) ->value : Symbol(value, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 41)) - -const checked = checkType<{x: number, y: string}>()({ ->checked : Symbol(checked, Decl(reverseMappedTypeIntersectionConstraint.ts, 39, 5)) ->checkType : Symbol(checkType, Decl(reverseMappedTypeIntersectionConstraint.ts, 37, 5)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 39, 27)) ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 39, 37)) - - x: 1 as number, ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 39, 53)) - - y: "y", ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 40, 17)) - - z: "z", // undesirable property z is *not* allowed ->z : Symbol(z, Decl(reverseMappedTypeIntersectionConstraint.ts, 41, 9)) - -}); - -checked; ->checked : Symbol(checked, Decl(reverseMappedTypeIntersectionConstraint.ts, 39, 5)) - -// ----------------------------------------------------------------------------------------- - -interface Stuff { ->Stuff : Symbol(Stuff, Decl(reverseMappedTypeIntersectionConstraint.ts, 45, 8)) - - field: number; ->field : Symbol(Stuff.field, Decl(reverseMappedTypeIntersectionConstraint.ts, 49, 17)) - - anotherField: string; ->anotherField : Symbol(Stuff.anotherField, Decl(reverseMappedTypeIntersectionConstraint.ts, 50, 18)) -} - -function doStuffWithStuff(s: { [K in keyof T & keyof Stuff]: T[K] } ): T { ->doStuffWithStuff : Symbol(doStuffWithStuff, Decl(reverseMappedTypeIntersectionConstraint.ts, 52, 1)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 26)) ->Stuff : Symbol(Stuff, Decl(reverseMappedTypeIntersectionConstraint.ts, 45, 8)) ->s : Symbol(s, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 43)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 49)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 26)) ->Stuff : Symbol(Stuff, Decl(reverseMappedTypeIntersectionConstraint.ts, 45, 8)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 26)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 49)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 26)) - - if(Math.random() > 0.5) { ->Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) - - return s as T ->s : Symbol(s, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 43)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 26)) - - } else { - return s ->s : Symbol(s, Decl(reverseMappedTypeIntersectionConstraint.ts, 54, 43)) - } -} - -doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) ->doStuffWithStuff : Symbol(doStuffWithStuff, Decl(reverseMappedTypeIntersectionConstraint.ts, 52, 1)) ->field : Symbol(field, Decl(reverseMappedTypeIntersectionConstraint.ts, 62, 18)) ->anotherField : Symbol(anotherField, Decl(reverseMappedTypeIntersectionConstraint.ts, 62, 28)) ->extra : Symbol(extra, Decl(reverseMappedTypeIntersectionConstraint.ts, 62, 47)) - -function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff]: T[K] }[]): T[] { ->doStuffWithStuffArr : Symbol(doStuffWithStuffArr, Decl(reverseMappedTypeIntersectionConstraint.ts, 62, 61)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 29)) ->Stuff : Symbol(Stuff, Decl(reverseMappedTypeIntersectionConstraint.ts, 45, 8)) ->arr : Symbol(arr, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 46)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 54)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 29)) ->Stuff : Symbol(Stuff, Decl(reverseMappedTypeIntersectionConstraint.ts, 45, 8)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 29)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 54)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 29)) - - if(Math.random() > 0.5) { ->Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) - - return arr as T[] ->arr : Symbol(arr, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 46)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 29)) - - } else { - return arr ->arr : Symbol(arr, Decl(reverseMappedTypeIntersectionConstraint.ts, 64, 46)) - } -} - -doStuffWithStuffArr([ ->doStuffWithStuffArr : Symbol(doStuffWithStuffArr, Decl(reverseMappedTypeIntersectionConstraint.ts, 62, 61)) - - { field: 1, anotherField: 'a', extra: 123 }, ->field : Symbol(field, Decl(reverseMappedTypeIntersectionConstraint.ts, 73, 5)) ->anotherField : Symbol(anotherField, Decl(reverseMappedTypeIntersectionConstraint.ts, 73, 15)) ->extra : Symbol(extra, Decl(reverseMappedTypeIntersectionConstraint.ts, 73, 34)) - -]) - -// ----------------------------------------------------------------------------------------- - -type XNumber = { x: number } ->XNumber : Symbol(XNumber, Decl(reverseMappedTypeIntersectionConstraint.ts, 74, 2)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 78, 16)) - -declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): void; ->foo : Symbol(foo, Decl(reverseMappedTypeIntersectionConstraint.ts, 78, 28)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 80, 21)) ->XNumber : Symbol(XNumber, Decl(reverseMappedTypeIntersectionConstraint.ts, 74, 2)) ->props : Symbol(props, Decl(reverseMappedTypeIntersectionConstraint.ts, 80, 40)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 80, 49)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 80, 21)) ->XNumber : Symbol(XNumber, Decl(reverseMappedTypeIntersectionConstraint.ts, 74, 2)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 80, 21)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 80, 49)) - -function bar(props: {x: number, y: string}) { ->bar : Symbol(bar, Decl(reverseMappedTypeIntersectionConstraint.ts, 80, 93)) ->props : Symbol(props, Decl(reverseMappedTypeIntersectionConstraint.ts, 82, 13)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 82, 21)) ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 82, 31)) - - return foo(props); // no error because lack of excess property check by design ->foo : Symbol(foo, Decl(reverseMappedTypeIntersectionConstraint.ts, 78, 28)) ->props : Symbol(props, Decl(reverseMappedTypeIntersectionConstraint.ts, 82, 13)) -} - -foo({x: 1, y: 'foo'}); ->foo : Symbol(foo, Decl(reverseMappedTypeIntersectionConstraint.ts, 78, 28)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 86, 5)) ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 86, 10)) - -foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design ->foo : Symbol(foo, Decl(reverseMappedTypeIntersectionConstraint.ts, 78, 28)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 88, 9)) ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 88, 14)) - -// ----------------------------------------------------------------------------------------- - -type NoErrWithOptProps = { x: number, y?: string } ->NoErrWithOptProps : Symbol(NoErrWithOptProps, Decl(reverseMappedTypeIntersectionConstraint.ts, 88, 27)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 92, 26)) ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 92, 37)) - -declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): void; ->baz : Symbol(baz, Decl(reverseMappedTypeIntersectionConstraint.ts, 92, 50)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 94, 21)) ->NoErrWithOptProps : Symbol(NoErrWithOptProps, Decl(reverseMappedTypeIntersectionConstraint.ts, 88, 27)) ->props : Symbol(props, Decl(reverseMappedTypeIntersectionConstraint.ts, 94, 50)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 94, 59)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 94, 21)) ->NoErrWithOptProps : Symbol(NoErrWithOptProps, Decl(reverseMappedTypeIntersectionConstraint.ts, 88, 27)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 94, 21)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 94, 59)) - -baz({x: 1}); ->baz : Symbol(baz, Decl(reverseMappedTypeIntersectionConstraint.ts, 92, 50)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 96, 5)) - -baz({x: 1, z: 123}); ->baz : Symbol(baz, Decl(reverseMappedTypeIntersectionConstraint.ts, 92, 50)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 97, 5)) ->z : Symbol(z, Decl(reverseMappedTypeIntersectionConstraint.ts, 97, 10)) - -baz({x: 1, y: 'foo'}); ->baz : Symbol(baz, Decl(reverseMappedTypeIntersectionConstraint.ts, 92, 50)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 98, 5)) ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 98, 10)) - -baz({x: 1, y: 'foo', z: 123}); ->baz : Symbol(baz, Decl(reverseMappedTypeIntersectionConstraint.ts, 92, 50)) ->x : Symbol(x, Decl(reverseMappedTypeIntersectionConstraint.ts, 99, 5)) ->y : Symbol(y, Decl(reverseMappedTypeIntersectionConstraint.ts, 99, 10)) ->z : Symbol(z, Decl(reverseMappedTypeIntersectionConstraint.ts, 99, 20)) - -// ----------------------------------------------------------------------------------------- - -interface WithNestedProp { ->WithNestedProp : Symbol(WithNestedProp, Decl(reverseMappedTypeIntersectionConstraint.ts, 99, 30)) - - prop: string; ->prop : Symbol(WithNestedProp.prop, Decl(reverseMappedTypeIntersectionConstraint.ts, 103, 26)) - - nested: { ->nested : Symbol(WithNestedProp.nested, Decl(reverseMappedTypeIntersectionConstraint.ts, 104, 15)) - - prop: string; ->prop : Symbol(prop, Decl(reverseMappedTypeIntersectionConstraint.ts, 105, 11)) - } -} - -declare function withNestedProp(props: {[K in keyof T & keyof WithNestedProp]: T[K]}): T; ->withNestedProp : Symbol(withNestedProp, Decl(reverseMappedTypeIntersectionConstraint.ts, 108, 1)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 110, 32)) ->WithNestedProp : Symbol(WithNestedProp, Decl(reverseMappedTypeIntersectionConstraint.ts, 99, 30)) ->props : Symbol(props, Decl(reverseMappedTypeIntersectionConstraint.ts, 110, 58)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 110, 67)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 110, 32)) ->WithNestedProp : Symbol(WithNestedProp, Decl(reverseMappedTypeIntersectionConstraint.ts, 99, 30)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 110, 32)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 110, 67)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 110, 32)) - -const wnp = withNestedProp({prop: 'foo', nested: { prop: 'bar' }, extra: 10 }); ->wnp : Symbol(wnp, Decl(reverseMappedTypeIntersectionConstraint.ts, 112, 5)) ->withNestedProp : Symbol(withNestedProp, Decl(reverseMappedTypeIntersectionConstraint.ts, 108, 1)) ->prop : Symbol(prop, Decl(reverseMappedTypeIntersectionConstraint.ts, 112, 28)) ->nested : Symbol(nested, Decl(reverseMappedTypeIntersectionConstraint.ts, 112, 40)) ->prop : Symbol(prop, Decl(reverseMappedTypeIntersectionConstraint.ts, 112, 50)) ->extra : Symbol(extra, Decl(reverseMappedTypeIntersectionConstraint.ts, 112, 65)) - -// ----------------------------------------------------------------------------------------- - -type IsLiteralString = string extends T ? false : true; ->IsLiteralString : Symbol(IsLiteralString, Decl(reverseMappedTypeIntersectionConstraint.ts, 112, 79)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 116, 21)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 116, 21)) - -type DeepWritable = T extends Function ? T : { -readonly [K in keyof T]: DeepWritable } ->DeepWritable : Symbol(DeepWritable, Decl(reverseMappedTypeIntersectionConstraint.ts, 116, 73)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 18)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 18)) ->Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 18)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 61)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 18)) ->DeepWritable : Symbol(DeepWritable, Decl(reverseMappedTypeIntersectionConstraint.ts, 116, 73)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 18)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 61)) - -interface ProvidedActor { ->ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 96)) - - src: string; ->src : Symbol(ProvidedActor.src, Decl(reverseMappedTypeIntersectionConstraint.ts, 120, 25)) - - logic: () => Promise; ->logic : Symbol(ProvidedActor.logic, Decl(reverseMappedTypeIntersectionConstraint.ts, 121, 14)) ->Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) -} - -type DistributeActors = TActor extends { src: infer TSrc } ->DistributeActors : Symbol(DistributeActors, Decl(reverseMappedTypeIntersectionConstraint.ts, 123, 1)) ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 125, 22)) ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 125, 22)) ->src : Symbol(src, Decl(reverseMappedTypeIntersectionConstraint.ts, 125, 48)) ->TSrc : Symbol(TSrc, Decl(reverseMappedTypeIntersectionConstraint.ts, 125, 59)) - - ? { - src: TSrc; ->src : Symbol(src, Decl(reverseMappedTypeIntersectionConstraint.ts, 126, 5)) ->TSrc : Symbol(TSrc, Decl(reverseMappedTypeIntersectionConstraint.ts, 125, 59)) - } - : never; - -interface MachineConfig { ->MachineConfig : Symbol(MachineConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 129, 10)) ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 131, 24)) ->ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 96)) - - types?: { ->types : Symbol(MachineConfig.types, Decl(reverseMappedTypeIntersectionConstraint.ts, 131, 55)) - - actors?: TActor; ->actors : Symbol(actors, Decl(reverseMappedTypeIntersectionConstraint.ts, 132, 11)) ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 131, 24)) - - }; - invoke: IsLiteralString extends true ->invoke : Symbol(MachineConfig.invoke, Decl(reverseMappedTypeIntersectionConstraint.ts, 134, 4)) ->IsLiteralString : Symbol(IsLiteralString, Decl(reverseMappedTypeIntersectionConstraint.ts, 112, 79)) ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 131, 24)) - - ? DistributeActors ->DistributeActors : Symbol(DistributeActors, Decl(reverseMappedTypeIntersectionConstraint.ts, 123, 1)) ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 131, 24)) - - : { - src: string; ->src : Symbol(src, Decl(reverseMappedTypeIntersectionConstraint.ts, 137, 7)) - - }; -} - -type NoExtra = { ->NoExtra : Symbol(NoExtra, Decl(reverseMappedTypeIntersectionConstraint.ts, 140, 1)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 142, 13)) - - [K in keyof T]: K extends keyof MachineConfig ? T[K] : never ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 143, 3)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 142, 13)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 143, 3)) ->MachineConfig : Symbol(MachineConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 129, 10)) ->T : Symbol(T, Decl(reverseMappedTypeIntersectionConstraint.ts, 142, 13)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 143, 3)) -} - -declare function createXMachine< ->createXMachine : Symbol(createXMachine, Decl(reverseMappedTypeIntersectionConstraint.ts, 144, 1)) - - const TConfig extends MachineConfig, ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 146, 32)) ->MachineConfig : Symbol(MachineConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 129, 10)) ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 147, 46)) - - TActor extends ProvidedActor = TConfig extends { types: { actors: ProvidedActor} } ? TConfig["types"]["actors"] : ProvidedActor, ->TActor : Symbol(TActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 147, 46)) ->ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 96)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 146, 32)) ->types : Symbol(types, Decl(reverseMappedTypeIntersectionConstraint.ts, 148, 50)) ->actors : Symbol(actors, Decl(reverseMappedTypeIntersectionConstraint.ts, 148, 59)) ->ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 96)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 146, 32)) ->ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeIntersectionConstraint.ts, 118, 96)) - ->(config: {[K in keyof MachineConfig & keyof TConfig]: TConfig[K] }): TConfig; ->config : Symbol(config, Decl(reverseMappedTypeIntersectionConstraint.ts, 149, 2)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 149, 12)) ->MachineConfig : Symbol(MachineConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 129, 10)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 146, 32)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 146, 32)) ->K : Symbol(K, Decl(reverseMappedTypeIntersectionConstraint.ts, 149, 12)) ->TConfig : Symbol(TConfig, Decl(reverseMappedTypeIntersectionConstraint.ts, 146, 32)) - -const child = () => Promise.resolve("foo"); ->child : Symbol(child, Decl(reverseMappedTypeIntersectionConstraint.ts, 151, 5)) - -const config = createXMachine({ ->config : Symbol(config, Decl(reverseMappedTypeIntersectionConstraint.ts, 153, 5)) ->createXMachine : Symbol(createXMachine, Decl(reverseMappedTypeIntersectionConstraint.ts, 144, 1)) - - types: {} as { ->types : Symbol(types, Decl(reverseMappedTypeIntersectionConstraint.ts, 153, 31)) - - actors: { ->actors : Symbol(actors, Decl(reverseMappedTypeIntersectionConstraint.ts, 154, 16)) - - src: "str"; ->src : Symbol(src, Decl(reverseMappedTypeIntersectionConstraint.ts, 155, 13)) - - logic: typeof child; ->logic : Symbol(logic, Decl(reverseMappedTypeIntersectionConstraint.ts, 156, 17)) ->child : Symbol(child, Decl(reverseMappedTypeIntersectionConstraint.ts, 151, 5)) - - }; - }, - invoke: { ->invoke : Symbol(invoke, Decl(reverseMappedTypeIntersectionConstraint.ts, 159, 4)) - - src: "str", ->src : Symbol(src, Decl(reverseMappedTypeIntersectionConstraint.ts, 160, 11)) - - }, - extra: 10 ->extra : Symbol(extra, Decl(reverseMappedTypeIntersectionConstraint.ts, 162, 4)) - -}); - -const config2 = createXMachine({ ->config2 : Symbol(config2, Decl(reverseMappedTypeIntersectionConstraint.ts, 166, 5)) ->createXMachine : Symbol(createXMachine, Decl(reverseMappedTypeIntersectionConstraint.ts, 144, 1)) - - invoke: { ->invoke : Symbol(invoke, Decl(reverseMappedTypeIntersectionConstraint.ts, 166, 32)) - - src: "whatever", ->src : Symbol(src, Decl(reverseMappedTypeIntersectionConstraint.ts, 167, 11)) - - }, - extra: 10 ->extra : Symbol(extra, Decl(reverseMappedTypeIntersectionConstraint.ts, 169, 4)) - -}); - diff --git a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.errors.txt b/tests/baselines/reference/reverseMappedTypeLimitedConstraint.errors.txt deleted file mode 100644 index dc6dc8fa3a331..0000000000000 --- a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -reverseMappedTypeLimitedConstraint.ts(5,13): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: 1; }'. -reverseMappedTypeLimitedConstraint.ts(14,3): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: "y"; }'. - - -==== reverseMappedTypeLimitedConstraint.ts (2 errors) ==== - type XNumber_ = { x: number } - - declare function foo_(props: {[K in keyof T & keyof XNumber_]: T[K]}): T; - - foo_({x: 1, y: 'foo'}); - ~ -!!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: 1; }'. - - // ----------------------------------------------------------------------------------------- - - const checkType_ = () => (value: { [K in keyof U & keyof T]: U[K] }) => value; - - const checked_ = checkType_<{x: number, y: string}>()({ - x: 1 as number, - y: "y", - z: "z", - ~ -!!! error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: "y"; }'. - }); \ No newline at end of file diff --git a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.js b/tests/baselines/reference/reverseMappedTypeLimitedConstraint.js deleted file mode 100644 index 0be7aa8d6a423..0000000000000 --- a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.js +++ /dev/null @@ -1,28 +0,0 @@ -//// [tests/cases/compiler/reverseMappedTypeLimitedConstraint.ts] //// - -//// [reverseMappedTypeLimitedConstraint.ts] -type XNumber_ = { x: number } - -declare function foo_(props: {[K in keyof T & keyof XNumber_]: T[K]}): T; - -foo_({x: 1, y: 'foo'}); - -// ----------------------------------------------------------------------------------------- - -const checkType_ = () => (value: { [K in keyof U & keyof T]: U[K] }) => value; - -const checked_ = checkType_<{x: number, y: string}>()({ - x: 1 as number, - y: "y", - z: "z", -}); - -//// [reverseMappedTypeLimitedConstraint.js] -foo_({ x: 1, y: 'foo' }); -// ----------------------------------------------------------------------------------------- -var checkType_ = function () { return function (value) { return value; }; }; -var checked_ = checkType_()({ - x: 1, - y: "y", - z: "z", -}); diff --git a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.symbols b/tests/baselines/reference/reverseMappedTypeLimitedConstraint.symbols deleted file mode 100644 index 5c81507278445..0000000000000 --- a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.symbols +++ /dev/null @@ -1,55 +0,0 @@ -//// [tests/cases/compiler/reverseMappedTypeLimitedConstraint.ts] //// - -=== reverseMappedTypeLimitedConstraint.ts === -type XNumber_ = { x: number } ->XNumber_ : Symbol(XNumber_, Decl(reverseMappedTypeLimitedConstraint.ts, 0, 0)) ->x : Symbol(x, Decl(reverseMappedTypeLimitedConstraint.ts, 0, 17)) - -declare function foo_(props: {[K in keyof T & keyof XNumber_]: T[K]}): T; ->foo_ : Symbol(foo_, Decl(reverseMappedTypeLimitedConstraint.ts, 0, 29)) ->T : Symbol(T, Decl(reverseMappedTypeLimitedConstraint.ts, 2, 22)) ->XNumber_ : Symbol(XNumber_, Decl(reverseMappedTypeLimitedConstraint.ts, 0, 0)) ->props : Symbol(props, Decl(reverseMappedTypeLimitedConstraint.ts, 2, 42)) ->K : Symbol(K, Decl(reverseMappedTypeLimitedConstraint.ts, 2, 51)) ->T : Symbol(T, Decl(reverseMappedTypeLimitedConstraint.ts, 2, 22)) ->XNumber_ : Symbol(XNumber_, Decl(reverseMappedTypeLimitedConstraint.ts, 0, 0)) ->T : Symbol(T, Decl(reverseMappedTypeLimitedConstraint.ts, 2, 22)) ->K : Symbol(K, Decl(reverseMappedTypeLimitedConstraint.ts, 2, 51)) ->T : Symbol(T, Decl(reverseMappedTypeLimitedConstraint.ts, 2, 22)) - -foo_({x: 1, y: 'foo'}); ->foo_ : Symbol(foo_, Decl(reverseMappedTypeLimitedConstraint.ts, 0, 29)) ->x : Symbol(x, Decl(reverseMappedTypeLimitedConstraint.ts, 4, 6)) ->y : Symbol(y, Decl(reverseMappedTypeLimitedConstraint.ts, 4, 11)) - -// ----------------------------------------------------------------------------------------- - -const checkType_ = () => (value: { [K in keyof U & keyof T]: U[K] }) => value; ->checkType_ : Symbol(checkType_, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 5)) ->T : Symbol(T, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 20)) ->U : Symbol(U, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 29)) ->T : Symbol(T, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 20)) ->value : Symbol(value, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 42)) ->K : Symbol(K, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 52)) ->U : Symbol(U, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 29)) ->T : Symbol(T, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 20)) ->U : Symbol(U, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 29)) ->K : Symbol(K, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 52)) ->value : Symbol(value, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 42)) - -const checked_ = checkType_<{x: number, y: string}>()({ ->checked_ : Symbol(checked_, Decl(reverseMappedTypeLimitedConstraint.ts, 10, 5)) ->checkType_ : Symbol(checkType_, Decl(reverseMappedTypeLimitedConstraint.ts, 8, 5)) ->x : Symbol(x, Decl(reverseMappedTypeLimitedConstraint.ts, 10, 29)) ->y : Symbol(y, Decl(reverseMappedTypeLimitedConstraint.ts, 10, 39)) - - x: 1 as number, ->x : Symbol(x, Decl(reverseMappedTypeLimitedConstraint.ts, 10, 55)) - - y: "y", ->y : Symbol(y, Decl(reverseMappedTypeLimitedConstraint.ts, 11, 17)) - - z: "z", ->z : Symbol(z, Decl(reverseMappedTypeLimitedConstraint.ts, 12, 9)) - -}); diff --git a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.types b/tests/baselines/reference/reverseMappedTypeLimitedConstraint.types deleted file mode 100644 index 821d7685fcccd..0000000000000 --- a/tests/baselines/reference/reverseMappedTypeLimitedConstraint.types +++ /dev/null @@ -1,52 +0,0 @@ -//// [tests/cases/compiler/reverseMappedTypeLimitedConstraint.ts] //// - -=== reverseMappedTypeLimitedConstraint.ts === -type XNumber_ = { x: number } ->XNumber_ : { x: number; } ->x : number - -declare function foo_(props: {[K in keyof T & keyof XNumber_]: T[K]}): T; ->foo_ : (props: { [K in keyof T & "x"]: T[K]; }) => T ->props : { [K in keyof T & "x"]: T[K]; } - -foo_({x: 1, y: 'foo'}); ->foo_({x: 1, y: 'foo'}) : { x: 1; } ->foo_ : (props: { [K in keyof T & "x"]: T[K]; }) => T ->{x: 1, y: 'foo'} : { x: 1; y: string; } ->x : 1 ->1 : 1 ->y : string ->'foo' : "foo" - -// ----------------------------------------------------------------------------------------- - -const checkType_ = () => (value: { [K in keyof U & keyof T]: U[K] }) => value; ->checkType_ : () => (value: { [K in keyof U & keyof T]: U[K]; }) => { [K in keyof U & keyof T]: U[K]; } ->() => (value: { [K in keyof U & keyof T]: U[K] }) => value : () => (value: { [K in keyof U & keyof T]: U[K]; }) => { [K in keyof U & keyof T]: U[K]; } ->(value: { [K in keyof U & keyof T]: U[K] }) => value : (value: { [K in keyof U & keyof T]: U[K]; }) => { [K in keyof U & keyof T]: U[K]; } ->value : { [K in keyof U & keyof T]: U[K]; } ->value : { [K in keyof U & keyof T]: U[K]; } - -const checked_ = checkType_<{x: number, y: string}>()({ ->checked_ : { x: number; y: "y"; } ->checkType_<{x: number, y: string}>()({ x: 1 as number, y: "y", z: "z",}) : { x: number; y: "y"; } ->checkType_<{x: number, y: string}>() : (value: { [K in keyof U & ("x" | "y")]: U[K]; }) => { [K in keyof U & ("x" | "y")]: U[K]; } ->checkType_ : () => (value: { [K in keyof U & keyof T]: U[K]; }) => { [K in keyof U & keyof T]: U[K]; } ->x : number ->y : string ->{ x: 1 as number, y: "y", z: "z",} : { x: number; y: "y"; z: string; } - - x: 1 as number, ->x : number ->1 as number : number ->1 : 1 - - y: "y", ->y : "y" ->"y" : "y" - - z: "z", ->z : string ->"z" : "z" - -}); diff --git a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.errors.txt b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.errors.txt similarity index 57% rename from tests/baselines/reference/reverseMappedTypeIntersectionConstraint.errors.txt rename to tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.errors.txt index ec7eab991b0ed..2f8ea60856ccf 100644 --- a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.errors.txt +++ b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.errors.txt @@ -1,32 +1,27 @@ -reverseMappedTypeIntersectionConstraint.ts(19,7): error TS2322: Type '"bar"' is not assignable to type '"foo"'. -reverseMappedTypeIntersectionConstraint.ts(32,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: "foo"; states: { a: { entry: "foo"; }; }; }'. -reverseMappedTypeIntersectionConstraint.ts(43,3): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: "y"; }'. -reverseMappedTypeIntersectionConstraint.ts(59,7): error TS2322: Type '{ [K in keyof T & keyof Stuff]: T[K]; }' is not assignable to type 'T'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(15,7): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(28,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: "foo"; states: { a: { entry: "foo"; }; }; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(39,3): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: "y"; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(53,7): error TS2322: Type '{ [K in keyof T & keyof Stuff]: T[K]; }' is not assignable to type 'T'. '{ [K in keyof T & keyof Stuff]: T[K]; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Stuff'. -reverseMappedTypeIntersectionConstraint.ts(63,49): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ field: 1; anotherField: "a"; }'. -reverseMappedTypeIntersectionConstraint.ts(69,7): error TS2322: Type '{ [K in keyof T & keyof Stuff]: T[K]; }[]' is not assignable to type 'T[]'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(57,64): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ field: 1; anotherField: "a"; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(63,7): error TS2322: Type '{ [K in keyof T & keyof Stuff]: T[K]; }[]' is not assignable to type 'T[]'. Type '{ [K in keyof T & keyof Stuff]: T[K]; }' is not assignable to type 'T'. '{ [K in keyof T & keyof Stuff]: T[K]; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Stuff'. -reverseMappedTypeIntersectionConstraint.ts(74,36): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ field: 1; anotherField: "a"; }'. -reverseMappedTypeIntersectionConstraint.ts(87,12): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: 1; }'. -reverseMappedTypeIntersectionConstraint.ts(98,12): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: 1; }'. -reverseMappedTypeIntersectionConstraint.ts(100,22): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: 1; y: "foo"; }'. -reverseMappedTypeIntersectionConstraint.ts(113,67): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ prop: "foo"; nested: { prop: string; }; }'. -reverseMappedTypeIntersectionConstraint.ts(152,21): error TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. -reverseMappedTypeIntersectionConstraint.ts(164,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ types: { actors: { src: "str"; logic: () => any; }; }; invoke: { readonly src: "str"; }; }'. -reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ invoke: { readonly src: "whatever"; }; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(68,36): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ field: 1; anotherField: "a"; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(81,25): error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: 1; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(92,25): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: 1; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(94,35): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: 1; y: "foo"; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(107,67): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ prop: "foo"; nested: { prop: string; }; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(152,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ types: { actors: { src: "str"; logic: () => Promise; }; }; invoke: { readonly src: "str"; }; }'. +reverseMappedTypeLimitedConstraintWithIntersection1.ts(159,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ invoke: { readonly src: "whatever"; }; }'. -==== reverseMappedTypeIntersectionConstraint.ts (14 errors) ==== +==== reverseMappedTypeLimitedConstraintWithIntersection1.ts (13 errors) ==== type StateConfig = { entry?: TAction states?: Record>; }; - type StateSchema = { - states?: Record; - }; - declare function createMachine< TConfig extends StateConfig, TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string, @@ -39,7 +34,7 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal entry: "bar", ~~~~~ !!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. -!!! related TS6500 reverseMappedTypeIntersectionConstraint.ts:2:3: The expected type comes from property 'entry' which is declared here on type 'StateConfig<"foo">' +!!! related TS6500 reverseMappedTypeLimitedConstraintWithIntersection1.ts:2:3: The expected type comes from property 'entry' which is declared here on type 'StateConfig<"foo">' }, }, extra: 12, @@ -70,8 +65,6 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal !!! error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: "y"; }'. }); - checked; - // ----------------------------------------------------------------------------------------- interface Stuff { @@ -90,8 +83,8 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal } } - doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) - ~~~~~ + const stuff1 = doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) + ~~~~~ !!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ field: 1; anotherField: "a"; }'. function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff]: T[K] }[]): T[] { @@ -106,7 +99,7 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal } } - doStuffWithStuffArr([ + const stuff2 = doStuffWithStuffArr([ { field: 1, anotherField: 'a', extra: 123 }, ~~~~~ !!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ field: 1; anotherField: "a"; }'. @@ -116,31 +109,31 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal type XNumber = { x: number } - declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): void; + declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): T; function bar(props: {x: number, y: string}) { return foo(props); // no error because lack of excess property check by design } - foo({x: 1, y: 'foo'}); - ~ + const foo1 = foo({x: 1, y: 'foo'}); + ~ !!! error TS2353: Object literal may only specify known properties, and 'y' does not exist in type '{ x: 1; }'. - foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design + const foo2 = foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design // ----------------------------------------------------------------------------------------- type NoErrWithOptProps = { x: number, y?: string } - declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): void; + declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): T; - baz({x: 1}); - baz({x: 1, z: 123}); - ~ + const baz1 = baz({x: 1}); + const baz2 = baz({x: 1, z: 123}); + ~ !!! error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: 1; }'. - baz({x: 1, y: 'foo'}); - baz({x: 1, y: 'foo', z: 123}); - ~ + const baz3 = baz({x: 1, y: 'foo'}); + const baz4 = baz({x: 1, y: 'foo', z: 123}); + ~ !!! error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: 1; y: "foo"; }'. // ----------------------------------------------------------------------------------------- @@ -162,8 +155,6 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal type IsLiteralString = string extends T ? false : true; - type DeepWritable = T extends Function ? T : { -readonly [K in keyof T]: DeepWritable } - interface ProvidedActor { src: string; logic: () => Promise; @@ -186,18 +177,12 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal }; } - type NoExtra = { - [K in keyof T]: K extends keyof MachineConfig ? T[K] : never - } - declare function createXMachine< const TConfig extends MachineConfig, TActor extends ProvidedActor = TConfig extends { types: { actors: ProvidedActor} } ? TConfig["types"]["actors"] : ProvidedActor, >(config: {[K in keyof MachineConfig & keyof TConfig]: TConfig[K] }): TConfig; const child = () => Promise.resolve("foo"); - ~~~~~~~ -!!! error TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later. const config = createXMachine({ types: {} as { @@ -211,7 +196,7 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal }, extra: 10 ~~~~~ -!!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ types: { actors: { src: "str"; logic: () => any; }; }; invoke: { readonly src: "str"; }; }'. +!!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ types: { actors: { src: "str"; logic: () => Promise; }; }; invoke: { readonly src: "str"; }; }'. }); const config2 = createXMachine({ @@ -222,4 +207,73 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal ~~~~~ !!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ invoke: { readonly src: "whatever"; }; }'. }); + + declare function fn1>(obj: { + [K in keyof T & "a"]: T[K]; + }): T; + const obj1 = { + a: 42, + b: true, + }; + const result1 = fn1(obj1); + + declare function fn2>(obj: { + [K in (keyof T & "a") | "b"]: T[K]; + }): T; + const obj2 = { + a: 42, + b: 100, + c: true, + }; + const result2 = fn2(obj2); + + declare function fn3(obj: { + [K in keyof T1 & keyof T2]: { + v1: T1[K]; + v2: T2[K]; + }; + }): [T1, T2]; + + const result3 = fn3({ + a: { + v1: "foo", + v2: 100, + }, + b: { + v1: true, + v2: null, + }, + }); + + declare function fn4>(arg: { + [K in keyof T & keyof E]: { + data: T[K]; + onSuccess: (data: T[K]) => void; + error: E[K]; + onError: (data: E[K]) => void; + }; + }): [T, E]; + + const result4 = fn4({ + a: { + data: "foo", + onSuccess: (dataArg) => { + dataArg; + }, + error: 404, + onError: (errorArg) => { + errorArg; + }, + }, + b: { + data: true, + onSuccess: (dataArg) => { + dataArg; + }, + error: 500, + onError: (errorArg) => { + errorArg; + }, + }, + }); \ No newline at end of file diff --git a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.js b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.js similarity index 64% rename from tests/baselines/reference/reverseMappedTypeIntersectionConstraint.js rename to tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.js index a68576c793bf8..85ab461ec949b 100644 --- a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.js +++ b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.js @@ -1,15 +1,11 @@ -//// [tests/cases/compiler/reverseMappedTypeIntersectionConstraint.ts] //// +//// [tests/cases/compiler/reverseMappedTypeLimitedConstraintWithIntersection1.ts] //// -//// [reverseMappedTypeIntersectionConstraint.ts] +//// [reverseMappedTypeLimitedConstraintWithIntersection1.ts] type StateConfig = { entry?: TAction states?: Record>; }; -type StateSchema = { - states?: Record; -}; - declare function createMachine< TConfig extends StateConfig, TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string, @@ -46,8 +42,6 @@ const checked = checkType<{x: number, y: string}>()({ z: "z", // undesirable property z is *not* allowed }); -checked; - // ----------------------------------------------------------------------------------------- interface Stuff { @@ -63,7 +57,7 @@ function doStuffWithStuff(s: { [K in keyof T & keyof Stuff]: T[ } } -doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) +const stuff1 = doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff]: T[K] }[]): T[] { if(Math.random() > 0.5) { @@ -73,7 +67,7 @@ function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff } } -doStuffWithStuffArr([ +const stuff2 = doStuffWithStuffArr([ { field: 1, anotherField: 'a', extra: 123 }, ]) @@ -81,26 +75,26 @@ doStuffWithStuffArr([ type XNumber = { x: number } -declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): void; +declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): T; function bar(props: {x: number, y: string}) { return foo(props); // no error because lack of excess property check by design } -foo({x: 1, y: 'foo'}); +const foo1 = foo({x: 1, y: 'foo'}); -foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design +const foo2 = foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design // ----------------------------------------------------------------------------------------- type NoErrWithOptProps = { x: number, y?: string } -declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): void; +declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): T; -baz({x: 1}); -baz({x: 1, z: 123}); -baz({x: 1, y: 'foo'}); -baz({x: 1, y: 'foo', z: 123}); +const baz1 = baz({x: 1}); +const baz2 = baz({x: 1, z: 123}); +const baz3 = baz({x: 1, y: 'foo'}); +const baz4 = baz({x: 1, y: 'foo', z: 123}); // ----------------------------------------------------------------------------------------- @@ -119,8 +113,6 @@ const wnp = withNestedProp({prop: 'foo', nested: { prop: 'bar' }, extra: 10 }); type IsLiteralString = string extends T ? false : true; -type DeepWritable = T extends Function ? T : { -readonly [K in keyof T]: DeepWritable } - interface ProvidedActor { src: string; logic: () => Promise; @@ -143,10 +135,6 @@ interface MachineConfig { }; } -type NoExtra = { - [K in keyof T]: K extends keyof MachineConfig ? T[K] : never -} - declare function createXMachine< const TConfig extends MachineConfig, TActor extends ProvidedActor = TConfig extends { types: { actors: ProvidedActor} } ? TConfig["types"]["actors"] : ProvidedActor, @@ -173,9 +161,78 @@ const config2 = createXMachine({ }, extra: 10 }); + +declare function fn1>(obj: { + [K in keyof T & "a"]: T[K]; +}): T; +const obj1 = { + a: 42, + b: true, +}; +const result1 = fn1(obj1); + +declare function fn2>(obj: { + [K in (keyof T & "a") | "b"]: T[K]; +}): T; +const obj2 = { + a: 42, + b: 100, + c: true, +}; +const result2 = fn2(obj2); + +declare function fn3(obj: { + [K in keyof T1 & keyof T2]: { + v1: T1[K]; + v2: T2[K]; + }; +}): [T1, T2]; + +const result3 = fn3({ + a: { + v1: "foo", + v2: 100, + }, + b: { + v1: true, + v2: null, + }, +}); + +declare function fn4>(arg: { + [K in keyof T & keyof E]: { + data: T[K]; + onSuccess: (data: T[K]) => void; + error: E[K]; + onError: (data: E[K]) => void; + }; +}): [T, E]; + +const result4 = fn4({ + a: { + data: "foo", + onSuccess: (dataArg) => { + dataArg; + }, + error: 404, + onError: (errorArg) => { + errorArg; + }, + }, + b: { + data: true, + onSuccess: (dataArg) => { + dataArg; + }, + error: 500, + onError: (errorArg) => { + errorArg; + }, + }, +}); -//// [reverseMappedTypeIntersectionConstraint.js] +//// [reverseMappedTypeLimitedConstraintWithIntersection1.js] "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { @@ -213,7 +270,6 @@ var checked = checkType()({ y: "y", z: "z", // undesirable property z is *not* allowed }); -checked; function doStuffWithStuff(s) { if (Math.random() > 0.5) { return s; @@ -222,7 +278,7 @@ function doStuffWithStuff(s) { return s; } } -doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }); +var stuff1 = doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }); function doStuffWithStuffArr(arr) { if (Math.random() > 0.5) { return arr; @@ -231,18 +287,18 @@ function doStuffWithStuffArr(arr) { return arr; } } -doStuffWithStuffArr([ +var stuff2 = doStuffWithStuffArr([ { field: 1, anotherField: 'a', extra: 123 }, ]); function bar(props) { return foo(props); // no error because lack of excess property check by design } -foo({ x: 1, y: 'foo' }); -foo(__assign({ x: 1, y: 'foo' })); // no error because lack of excess property check by design -baz({ x: 1 }); -baz({ x: 1, z: 123 }); -baz({ x: 1, y: 'foo' }); -baz({ x: 1, y: 'foo', z: 123 }); +var foo1 = foo({ x: 1, y: 'foo' }); +var foo2 = foo(__assign({ x: 1, y: 'foo' })); // no error because lack of excess property check by design +var baz1 = baz({ x: 1 }); +var baz2 = baz({ x: 1, z: 123 }); +var baz3 = baz({ x: 1, y: 'foo' }); +var baz4 = baz({ x: 1, y: 'foo', z: 123 }); var wnp = withNestedProp({ prop: 'foo', nested: { prop: 'bar' }, extra: 10 }); var child = function () { return Promise.resolve("foo"); }; var config = createXMachine({ @@ -258,3 +314,46 @@ var config2 = createXMachine({ }, extra: 10 }); +var obj1 = { + a: 42, + b: true, +}; +var result1 = fn1(obj1); +var obj2 = { + a: 42, + b: 100, + c: true, +}; +var result2 = fn2(obj2); +var result3 = fn3({ + a: { + v1: "foo", + v2: 100, + }, + b: { + v1: true, + v2: null, + }, +}); +var result4 = fn4({ + a: { + data: "foo", + onSuccess: function (dataArg) { + dataArg; + }, + error: 404, + onError: function (errorArg) { + errorArg; + }, + }, + b: { + data: true, + onSuccess: function (dataArg) { + dataArg; + }, + error: 500, + onError: function (errorArg) { + errorArg; + }, + }, +}); diff --git a/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.symbols b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.symbols new file mode 100644 index 0000000000000..f4499293c4aca --- /dev/null +++ b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.symbols @@ -0,0 +1,678 @@ +//// [tests/cases/compiler/reverseMappedTypeLimitedConstraintWithIntersection1.ts] //// + +=== reverseMappedTypeLimitedConstraintWithIntersection1.ts === +type StateConfig = { +>StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 0)) +>TAction : Symbol(TAction, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 17)) + + entry?: TAction +>entry : Symbol(entry, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 44)) +>TAction : Symbol(TAction, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 17)) + + states?: Record>; +>states : Symbol(states, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 1, 17)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 0)) +>TAction : Symbol(TAction, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 17)) + +}; + +declare function createMachine< +>createMachine : Symbol(createMachine, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 3, 2)) + + TConfig extends StateConfig, +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 5, 31)) +>StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 0)) +>TAction : Symbol(TAction, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 6, 39)) + + TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string, +>TAction : Symbol(TAction, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 6, 39)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 5, 31)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 5, 31)) + +>(config: { [K in keyof TConfig & keyof StateConfig]: TConfig[K] }): [TAction, TConfig]; +>config : Symbol(config, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 8, 2)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 8, 13)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 5, 31)) +>StateConfig : Symbol(StateConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 0, 0)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 5, 31)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 8, 13)) +>TAction : Symbol(TAction, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 6, 39)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 5, 31)) + +const inferredParams1 = createMachine({ +>inferredParams1 : Symbol(inferredParams1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 10, 5)) +>createMachine : Symbol(createMachine, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 3, 2)) + + entry: "foo", +>entry : Symbol(entry, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 10, 39)) + + states: { +>states : Symbol(states, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 11, 15)) + + a: { +>a : Symbol(a, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 12, 11)) + + entry: "bar", +>entry : Symbol(entry, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 13, 8)) + + }, + }, + extra: 12, +>extra : Symbol(extra, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 16, 4)) + +}); + +const inferredParams2 = createMachine({ +>inferredParams2 : Symbol(inferredParams2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 20, 5)) +>createMachine : Symbol(createMachine, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 3, 2)) + + entry: "foo", +>entry : Symbol(entry, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 20, 39)) + + states: { +>states : Symbol(states, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 21, 15)) + + a: { +>a : Symbol(a, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 22, 11)) + + entry: "foo", +>entry : Symbol(entry, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 23, 8)) + + }, + }, + extra: 12, +>extra : Symbol(extra, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 26, 4)) + +}); + + +// ----------------------------------------------------------------------------------------- + +const checkType = () => (value: { [K in keyof U & keyof T]: U[K] }) => value; +>checkType : Symbol(checkType, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 5)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 19)) +>U : Symbol(U, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 28)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 19)) +>value : Symbol(value, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 41)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 51)) +>U : Symbol(U, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 28)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 19)) +>U : Symbol(U, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 28)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 51)) +>value : Symbol(value, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 41)) + +const checked = checkType<{x: number, y: string}>()({ +>checked : Symbol(checked, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 35, 5)) +>checkType : Symbol(checkType, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 33, 5)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 35, 27)) +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 35, 37)) + + x: 1 as number, +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 35, 53)) + + y: "y", +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 36, 17)) + + z: "z", // undesirable property z is *not* allowed +>z : Symbol(z, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 37, 9)) + +}); + +// ----------------------------------------------------------------------------------------- + +interface Stuff { +>Stuff : Symbol(Stuff, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 39, 3)) + + field: number; +>field : Symbol(Stuff.field, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 43, 17)) + + anotherField: string; +>anotherField : Symbol(Stuff.anotherField, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 44, 18)) +} + +function doStuffWithStuff(s: { [K in keyof T & keyof Stuff]: T[K] } ): T { +>doStuffWithStuff : Symbol(doStuffWithStuff, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 46, 1)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 26)) +>Stuff : Symbol(Stuff, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 39, 3)) +>s : Symbol(s, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 43)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 49)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 26)) +>Stuff : Symbol(Stuff, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 39, 3)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 26)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 49)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 26)) + + if(Math.random() > 0.5) { +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + return s as T +>s : Symbol(s, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 43)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 26)) + + } else { + return s +>s : Symbol(s, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 48, 43)) + } +} + +const stuff1 = doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) +>stuff1 : Symbol(stuff1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 56, 5)) +>doStuffWithStuff : Symbol(doStuffWithStuff, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 46, 1)) +>field : Symbol(field, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 56, 33)) +>anotherField : Symbol(anotherField, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 56, 43)) +>extra : Symbol(extra, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 56, 62)) + +function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff]: T[K] }[]): T[] { +>doStuffWithStuffArr : Symbol(doStuffWithStuffArr, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 56, 76)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 29)) +>Stuff : Symbol(Stuff, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 39, 3)) +>arr : Symbol(arr, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 46)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 54)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 29)) +>Stuff : Symbol(Stuff, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 39, 3)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 29)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 54)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 29)) + + if(Math.random() > 0.5) { +>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) + + return arr as T[] +>arr : Symbol(arr, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 46)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 29)) + + } else { + return arr +>arr : Symbol(arr, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 58, 46)) + } +} + +const stuff2 = doStuffWithStuffArr([ +>stuff2 : Symbol(stuff2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 66, 5)) +>doStuffWithStuffArr : Symbol(doStuffWithStuffArr, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 56, 76)) + + { field: 1, anotherField: 'a', extra: 123 }, +>field : Symbol(field, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 67, 5)) +>anotherField : Symbol(anotherField, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 67, 15)) +>extra : Symbol(extra, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 67, 34)) + +]) + +// ----------------------------------------------------------------------------------------- + +type XNumber = { x: number } +>XNumber : Symbol(XNumber, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 68, 2)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 72, 16)) + +declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): T; +>foo : Symbol(foo, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 72, 28)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 21)) +>XNumber : Symbol(XNumber, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 68, 2)) +>props : Symbol(props, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 40)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 49)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 21)) +>XNumber : Symbol(XNumber, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 68, 2)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 21)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 49)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 21)) + +function bar(props: {x: number, y: string}) { +>bar : Symbol(bar, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 74, 90)) +>props : Symbol(props, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 76, 13)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 76, 21)) +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 76, 31)) + + return foo(props); // no error because lack of excess property check by design +>foo : Symbol(foo, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 72, 28)) +>props : Symbol(props, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 76, 13)) +} + +const foo1 = foo({x: 1, y: 'foo'}); +>foo1 : Symbol(foo1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 80, 5)) +>foo : Symbol(foo, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 72, 28)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 80, 18)) +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 80, 23)) + +const foo2 = foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design +>foo2 : Symbol(foo2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 82, 5)) +>foo : Symbol(foo, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 72, 28)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 82, 22)) +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 82, 27)) + +// ----------------------------------------------------------------------------------------- + +type NoErrWithOptProps = { x: number, y?: string } +>NoErrWithOptProps : Symbol(NoErrWithOptProps, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 82, 40)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 86, 26)) +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 86, 37)) + +declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): T; +>baz : Symbol(baz, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 86, 50)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 88, 21)) +>NoErrWithOptProps : Symbol(NoErrWithOptProps, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 82, 40)) +>props : Symbol(props, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 88, 50)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 88, 59)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 88, 21)) +>NoErrWithOptProps : Symbol(NoErrWithOptProps, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 82, 40)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 88, 21)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 88, 59)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 88, 21)) + +const baz1 = baz({x: 1}); +>baz1 : Symbol(baz1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 90, 5)) +>baz : Symbol(baz, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 86, 50)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 90, 18)) + +const baz2 = baz({x: 1, z: 123}); +>baz2 : Symbol(baz2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 91, 5)) +>baz : Symbol(baz, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 86, 50)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 91, 18)) +>z : Symbol(z, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 91, 23)) + +const baz3 = baz({x: 1, y: 'foo'}); +>baz3 : Symbol(baz3, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 92, 5)) +>baz : Symbol(baz, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 86, 50)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 92, 18)) +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 92, 23)) + +const baz4 = baz({x: 1, y: 'foo', z: 123}); +>baz4 : Symbol(baz4, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 93, 5)) +>baz : Symbol(baz, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 86, 50)) +>x : Symbol(x, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 93, 18)) +>y : Symbol(y, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 93, 23)) +>z : Symbol(z, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 93, 33)) + +// ----------------------------------------------------------------------------------------- + +interface WithNestedProp { +>WithNestedProp : Symbol(WithNestedProp, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 93, 43)) + + prop: string; +>prop : Symbol(WithNestedProp.prop, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 97, 26)) + + nested: { +>nested : Symbol(WithNestedProp.nested, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 98, 15)) + + prop: string; +>prop : Symbol(prop, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 99, 11)) + } +} + +declare function withNestedProp(props: {[K in keyof T & keyof WithNestedProp]: T[K]}): T; +>withNestedProp : Symbol(withNestedProp, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 102, 1)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 104, 32)) +>WithNestedProp : Symbol(WithNestedProp, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 93, 43)) +>props : Symbol(props, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 104, 58)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 104, 67)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 104, 32)) +>WithNestedProp : Symbol(WithNestedProp, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 93, 43)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 104, 32)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 104, 67)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 104, 32)) + +const wnp = withNestedProp({prop: 'foo', nested: { prop: 'bar' }, extra: 10 }); +>wnp : Symbol(wnp, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 106, 5)) +>withNestedProp : Symbol(withNestedProp, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 102, 1)) +>prop : Symbol(prop, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 106, 28)) +>nested : Symbol(nested, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 106, 40)) +>prop : Symbol(prop, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 106, 50)) +>extra : Symbol(extra, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 106, 65)) + +// ----------------------------------------------------------------------------------------- + +type IsLiteralString = string extends T ? false : true; +>IsLiteralString : Symbol(IsLiteralString, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 106, 79)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 110, 21)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 110, 21)) + +interface ProvidedActor { +>ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 110, 73)) + + src: string; +>src : Symbol(ProvidedActor.src, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 112, 25)) + + logic: () => Promise; +>logic : Symbol(ProvidedActor.logic, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 113, 14)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +} + +type DistributeActors = TActor extends { src: infer TSrc } +>DistributeActors : Symbol(DistributeActors, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 115, 1)) +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 117, 22)) +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 117, 22)) +>src : Symbol(src, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 117, 48)) +>TSrc : Symbol(TSrc, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 117, 59)) + + ? { + src: TSrc; +>src : Symbol(src, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 118, 5)) +>TSrc : Symbol(TSrc, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 117, 59)) + } + : never; + +interface MachineConfig { +>MachineConfig : Symbol(MachineConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 121, 10)) +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 123, 24)) +>ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 110, 73)) + + types?: { +>types : Symbol(MachineConfig.types, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 123, 55)) + + actors?: TActor; +>actors : Symbol(actors, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 124, 11)) +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 123, 24)) + + }; + invoke: IsLiteralString extends true +>invoke : Symbol(MachineConfig.invoke, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 126, 4)) +>IsLiteralString : Symbol(IsLiteralString, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 106, 79)) +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 123, 24)) + + ? DistributeActors +>DistributeActors : Symbol(DistributeActors, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 115, 1)) +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 123, 24)) + + : { + src: string; +>src : Symbol(src, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 129, 7)) + + }; +} + +declare function createXMachine< +>createXMachine : Symbol(createXMachine, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 132, 1)) + + const TConfig extends MachineConfig, +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 134, 32)) +>MachineConfig : Symbol(MachineConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 121, 10)) +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 135, 46)) + + TActor extends ProvidedActor = TConfig extends { types: { actors: ProvidedActor} } ? TConfig["types"]["actors"] : ProvidedActor, +>TActor : Symbol(TActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 135, 46)) +>ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 110, 73)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 134, 32)) +>types : Symbol(types, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 136, 50)) +>actors : Symbol(actors, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 136, 59)) +>ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 110, 73)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 134, 32)) +>ProvidedActor : Symbol(ProvidedActor, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 110, 73)) + +>(config: {[K in keyof MachineConfig & keyof TConfig]: TConfig[K] }): TConfig; +>config : Symbol(config, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 137, 2)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 137, 12)) +>MachineConfig : Symbol(MachineConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 121, 10)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 134, 32)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 134, 32)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 137, 12)) +>TConfig : Symbol(TConfig, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 134, 32)) + +const child = () => Promise.resolve("foo"); +>child : Symbol(child, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 139, 5)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +const config = createXMachine({ +>config : Symbol(config, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 141, 5)) +>createXMachine : Symbol(createXMachine, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 132, 1)) + + types: {} as { +>types : Symbol(types, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 141, 31)) + + actors: { +>actors : Symbol(actors, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 142, 16)) + + src: "str"; +>src : Symbol(src, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 143, 13)) + + logic: typeof child; +>logic : Symbol(logic, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 144, 17)) +>child : Symbol(child, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 139, 5)) + + }; + }, + invoke: { +>invoke : Symbol(invoke, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 147, 4)) + + src: "str", +>src : Symbol(src, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 148, 11)) + + }, + extra: 10 +>extra : Symbol(extra, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 150, 4)) + +}); + +const config2 = createXMachine({ +>config2 : Symbol(config2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 154, 5)) +>createXMachine : Symbol(createXMachine, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 132, 1)) + + invoke: { +>invoke : Symbol(invoke, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 154, 32)) + + src: "whatever", +>src : Symbol(src, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 155, 11)) + + }, + extra: 10 +>extra : Symbol(extra, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 157, 4)) + +}); + +declare function fn1>(obj: { +>fn1 : Symbol(fn1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 159, 3)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 161, 21)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>obj : Symbol(obj, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 161, 55)) + + [K in keyof T & "a"]: T[K]; +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 162, 3)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 161, 21)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 161, 21)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 162, 3)) + +}): T; +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 161, 21)) + +const obj1 = { +>obj1 : Symbol(obj1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 164, 5)) + + a: 42, +>a : Symbol(a, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 164, 14)) + + b: true, +>b : Symbol(b, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 165, 8)) + +}; +const result1 = fn1(obj1); +>result1 : Symbol(result1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 168, 5)) +>fn1 : Symbol(fn1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 159, 3)) +>obj1 : Symbol(obj1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 164, 5)) + +declare function fn2>(obj: { +>fn2 : Symbol(fn2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 168, 26)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 170, 21)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>obj : Symbol(obj, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 170, 55)) + + [K in (keyof T & "a") | "b"]: T[K]; +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 171, 3)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 170, 21)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 170, 21)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 171, 3)) + +}): T; +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 170, 21)) + +const obj2 = { +>obj2 : Symbol(obj2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 173, 5)) + + a: 42, +>a : Symbol(a, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 173, 14)) + + b: 100, +>b : Symbol(b, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 174, 8)) + + c: true, +>c : Symbol(c, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 175, 9)) + +}; +const result2 = fn2(obj2); +>result2 : Symbol(result2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 178, 5)) +>fn2 : Symbol(fn2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 168, 26)) +>obj2 : Symbol(obj2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 173, 5)) + +declare function fn3(obj: { +>fn3 : Symbol(fn3, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 178, 26)) +>T1 : Symbol(T1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 21)) +>T2 : Symbol(T2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 24)) +>obj : Symbol(obj, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 29)) + + [K in keyof T1 & keyof T2]: { +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 181, 3)) +>T1 : Symbol(T1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 21)) +>T2 : Symbol(T2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 24)) + + v1: T1[K]; +>v1 : Symbol(v1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 181, 31)) +>T1 : Symbol(T1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 21)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 181, 3)) + + v2: T2[K]; +>v2 : Symbol(v2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 182, 14)) +>T2 : Symbol(T2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 24)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 181, 3)) + + }; +}): [T1, T2]; +>T1 : Symbol(T1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 21)) +>T2 : Symbol(T2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 180, 24)) + +const result3 = fn3({ +>result3 : Symbol(result3, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 187, 5)) +>fn3 : Symbol(fn3, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 178, 26)) + + a: { +>a : Symbol(a, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 187, 21)) + + v1: "foo", +>v1 : Symbol(v1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 188, 6)) + + v2: 100, +>v2 : Symbol(v2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 189, 14)) + + }, + b: { +>b : Symbol(b, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 191, 4)) + + v1: true, +>v1 : Symbol(v1, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 192, 6)) + + v2: null, +>v2 : Symbol(v2, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 193, 13)) + + }, +}); + +declare function fn4>(arg: { +>fn4 : Symbol(fn4, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 196, 3)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 21)) +>E : Symbol(E, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 23)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>arg : Symbol(arg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 58)) + + [K in keyof T & keyof E]: { +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 199, 3)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 21)) +>E : Symbol(E, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 23)) + + data: T[K]; +>data : Symbol(data, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 199, 29)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 21)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 199, 3)) + + onSuccess: (data: T[K]) => void; +>onSuccess : Symbol(onSuccess, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 200, 15)) +>data : Symbol(data, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 201, 16)) +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 21)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 199, 3)) + + error: E[K]; +>error : Symbol(error, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 201, 36)) +>E : Symbol(E, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 23)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 199, 3)) + + onError: (data: E[K]) => void; +>onError : Symbol(onError, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 202, 16)) +>data : Symbol(data, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 203, 14)) +>E : Symbol(E, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 23)) +>K : Symbol(K, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 199, 3)) + + }; +}): [T, E]; +>T : Symbol(T, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 21)) +>E : Symbol(E, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 198, 23)) + +const result4 = fn4({ +>result4 : Symbol(result4, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 207, 5)) +>fn4 : Symbol(fn4, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 196, 3)) + + a: { +>a : Symbol(a, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 207, 21)) + + data: "foo", +>data : Symbol(data, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 208, 6)) + + onSuccess: (dataArg) => { +>onSuccess : Symbol(onSuccess, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 209, 16)) +>dataArg : Symbol(dataArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 210, 16)) + + dataArg; +>dataArg : Symbol(dataArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 210, 16)) + + }, + error: 404, +>error : Symbol(error, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 212, 6)) + + onError: (errorArg) => { +>onError : Symbol(onError, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 213, 15)) +>errorArg : Symbol(errorArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 214, 14)) + + errorArg; +>errorArg : Symbol(errorArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 214, 14)) + + }, + }, + b: { +>b : Symbol(b, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 217, 4)) + + data: true, +>data : Symbol(data, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 218, 6)) + + onSuccess: (dataArg) => { +>onSuccess : Symbol(onSuccess, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 219, 15)) +>dataArg : Symbol(dataArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 220, 16)) + + dataArg; +>dataArg : Symbol(dataArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 220, 16)) + + }, + error: 500, +>error : Symbol(error, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 222, 6)) + + onError: (errorArg) => { +>onError : Symbol(onError, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 223, 15)) +>errorArg : Symbol(errorArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 224, 14)) + + errorArg; +>errorArg : Symbol(errorArg, Decl(reverseMappedTypeLimitedConstraintWithIntersection1.ts, 224, 14)) + + }, + }, +}); + diff --git a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.types b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.types similarity index 62% rename from tests/baselines/reference/reverseMappedTypeIntersectionConstraint.types rename to tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.types index 43b568dd83d87..e66efc74dd7b8 100644 --- a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.types +++ b/tests/baselines/reference/reverseMappedTypeLimitedConstraintWithIntersection1.types @@ -1,6 +1,6 @@ -//// [tests/cases/compiler/reverseMappedTypeIntersectionConstraint.ts] //// +//// [tests/cases/compiler/reverseMappedTypeLimitedConstraintWithIntersection1.ts] //// -=== reverseMappedTypeIntersectionConstraint.ts === +=== reverseMappedTypeLimitedConstraintWithIntersection1.ts === type StateConfig = { >StateConfig : StateConfig @@ -12,14 +12,6 @@ type StateConfig = { }; -type StateSchema = { ->StateSchema : { states?: Record | undefined; } - - states?: Record; ->states : Record | undefined - -}; - declare function createMachine< >createMachine : , TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string>(config: { [K in keyof TConfig & keyof StateConfig]: TConfig[K]; }) => [TAction, TConfig] @@ -122,9 +114,6 @@ const checked = checkType<{x: number, y: string}>()({ }); -checked; ->checked : { x: number; y: "y"; } - // ----------------------------------------------------------------------------------------- interface Stuff { @@ -157,7 +146,8 @@ function doStuffWithStuff(s: { [K in keyof T & keyof Stuff]: T[ } } -doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) +const stuff1 = doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) +>stuff1 : { field: 1; anotherField: "a"; } >doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) : { field: 1; anotherField: "a"; } >doStuffWithStuff : (s: { [K in keyof T & keyof Stuff]: T[K]; }) => T >{ field: 1, anotherField: 'a', extra: 123 } : { field: 1; anotherField: "a"; extra: number; } @@ -190,7 +180,8 @@ function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff } } -doStuffWithStuffArr([ +const stuff2 = doStuffWithStuffArr([ +>stuff2 : { field: 1; anotherField: "a"; }[] >doStuffWithStuffArr([ { field: 1, anotherField: 'a', extra: 123 },]) : { field: 1; anotherField: "a"; }[] >doStuffWithStuffArr : (arr: { [K in keyof T & keyof Stuff]: T[K]; }[]) => T[] >[ { field: 1, anotherField: 'a', extra: 123 },] : { field: 1; anotherField: "a"; extra: number; }[] @@ -212,34 +203,36 @@ type XNumber = { x: number } >XNumber : { x: number; } >x : number -declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): void; ->foo : (props: { [K in keyof T & "x"]: T[K]; }) => void +declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): T; +>foo : (props: { [K in keyof T & "x"]: T[K]; }) => T >props : { [K in keyof T & "x"]: T[K]; } function bar(props: {x: number, y: string}) { ->bar : (props: { x: number; y: string;}) => void +>bar : (props: { x: number; y: string;}) => { x: number; } >props : { x: number; y: string; } >x : number >y : string return foo(props); // no error because lack of excess property check by design ->foo(props) : void ->foo : (props: { [K in keyof T & "x"]: T[K]; }) => void +>foo(props) : { x: number; } +>foo : (props: { [K in keyof T & "x"]: T[K]; }) => T >props : { x: number; y: string; } } -foo({x: 1, y: 'foo'}); ->foo({x: 1, y: 'foo'}) : void ->foo : (props: { [K in keyof T & "x"]: T[K]; }) => void +const foo1 = foo({x: 1, y: 'foo'}); +>foo1 : { x: 1; } +>foo({x: 1, y: 'foo'}) : { x: 1; } +>foo : (props: { [K in keyof T & "x"]: T[K]; }) => T >{x: 1, y: 'foo'} : { x: 1; y: string; } >x : 1 >1 : 1 >y : string >'foo' : "foo" -foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design ->foo({...{x: 1, y: 'foo'}}) : void ->foo : (props: { [K in keyof T & "x"]: T[K]; }) => void +const foo2 = foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design +>foo2 : { x: 1; } +>foo({...{x: 1, y: 'foo'}}) : { x: 1; } +>foo : (props: { [K in keyof T & "x"]: T[K]; }) => T >{...{x: 1, y: 'foo'}} : { x: 1; y: string; } >{x: 1, y: 'foo'} : { x: 1; y: string; } >x : 1 @@ -254,38 +247,42 @@ type NoErrWithOptProps = { x: number, y?: string } >x : number >y : string | undefined -declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): void; ->baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => void +declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): T; +>baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => T >props : { [K in keyof T & keyof NoErrWithOptProps]: T[K]; } -baz({x: 1}); ->baz({x: 1}) : void ->baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => void +const baz1 = baz({x: 1}); +>baz1 : { x: 1; } +>baz({x: 1}) : { x: 1; } +>baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => T >{x: 1} : { x: 1; } >x : 1 >1 : 1 -baz({x: 1, z: 123}); ->baz({x: 1, z: 123}) : void ->baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => void +const baz2 = baz({x: 1, z: 123}); +>baz2 : { x: 1; } +>baz({x: 1, z: 123}) : { x: 1; } +>baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => T >{x: 1, z: 123} : { x: 1; z: number; } >x : 1 >1 : 1 >z : number >123 : 123 -baz({x: 1, y: 'foo'}); ->baz({x: 1, y: 'foo'}) : void ->baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => void +const baz3 = baz({x: 1, y: 'foo'}); +>baz3 : { x: 1; y: "foo"; } +>baz({x: 1, y: 'foo'}) : { x: 1; y: "foo"; } +>baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => T >{x: 1, y: 'foo'} : { x: 1; y: "foo"; } >x : 1 >1 : 1 >y : "foo" >'foo' : "foo" -baz({x: 1, y: 'foo', z: 123}); ->baz({x: 1, y: 'foo', z: 123}) : void ->baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => void +const baz4 = baz({x: 1, y: 'foo', z: 123}); +>baz4 : { x: 1; y: "foo"; } +>baz({x: 1, y: 'foo', z: 123}) : { x: 1; y: "foo"; } +>baz : (props: { [K in keyof T & keyof NoErrWithOptProps]: T[K]; }) => T >{x: 1, y: 'foo', z: 123} : { x: 1; y: "foo"; z: number; } >x : 1 >1 : 1 @@ -333,9 +330,6 @@ type IsLiteralString = string extends T ? false : true; >false : false >true : true -type DeepWritable = T extends Function ? T : { -readonly [K in keyof T]: DeepWritable } ->DeepWritable : DeepWritable - interface ProvidedActor { src: string; >src : string @@ -374,12 +368,6 @@ interface MachineConfig { }; } -type NoExtra = { ->NoExtra : NoExtra - - [K in keyof T]: K extends keyof MachineConfig ? T[K] : never -} - declare function createXMachine< >createXMachine : , TActor extends ProvidedActor = TConfig extends { types: { actors: ProvidedActor;}; } ? TConfig["types"]["actors"] : ProvidedActor>(config: { [K in keyof MachineConfig & keyof TConfig]: TConfig[K]; }) => TConfig @@ -392,12 +380,12 @@ declare function createXMachine< >config : { [K in keyof MachineConfig & keyof TConfig]: TConfig[K]; } const child = () => Promise.resolve("foo"); ->child : () => any ->() => Promise.resolve("foo") : () => any ->Promise.resolve("foo") : any ->Promise.resolve : any ->Promise : any ->resolve : any +>child : () => Promise +>() => Promise.resolve("foo") : () => Promise +>Promise.resolve("foo") : Promise +>Promise.resolve : { (): Promise; (value: T): Promise>; (value: T_1 | PromiseLike): Promise>; } +>Promise : PromiseConstructor +>resolve : { (): Promise; (value: T): Promise>; (value: T_1 | PromiseLike): Promise>; } >"foo" : "foo" const config = createXMachine({ @@ -418,8 +406,8 @@ const config = createXMachine({ >src : "str" logic: typeof child; ->logic : () => any ->child : () => any +>logic : () => Promise +>child : () => Promise }; }, @@ -459,3 +447,196 @@ const config2 = createXMachine({ }); +declare function fn1>(obj: { +>fn1 : >(obj: { [K in keyof T & "a"]: T[K]; }) => T +>obj : { [K in keyof T & "a"]: T[K]; } + + [K in keyof T & "a"]: T[K]; +}): T; +const obj1 = { +>obj1 : { a: number; b: boolean; } +>{ a: 42, b: true,} : { a: number; b: boolean; } + + a: 42, +>a : number +>42 : 42 + + b: true, +>b : boolean +>true : true + +}; +const result1 = fn1(obj1); +>result1 : { a: number; } +>fn1(obj1) : { a: number; } +>fn1 : >(obj: { [K in keyof T & "a"]: T[K]; }) => T +>obj1 : { a: number; b: boolean; } + +declare function fn2>(obj: { +>fn2 : >(obj: { [K in "b" | (keyof T & "a")]: T[K]; }) => T +>obj : { [K in "b" | (keyof T & "a")]: T[K]; } + + [K in (keyof T & "a") | "b"]: T[K]; +}): T; +const obj2 = { +>obj2 : { a: number; b: number; c: boolean; } +>{ a: 42, b: 100, c: true,} : { a: number; b: number; c: boolean; } + + a: 42, +>a : number +>42 : 42 + + b: 100, +>b : number +>100 : 100 + + c: true, +>c : boolean +>true : true + +}; +const result2 = fn2(obj2); +>result2 : { a: number; b: number; } +>fn2(obj2) : { a: number; b: number; } +>fn2 : >(obj: { [K in "b" | (keyof T & "a")]: T[K]; }) => T +>obj2 : { a: number; b: number; c: boolean; } + +declare function fn3(obj: { +>fn3 : (obj: { [K in keyof T1 & keyof T2]: { v1: T1[K]; v2: T2[K]; }; }) => [T1, T2] +>obj : { [K in keyof T1 & keyof T2]: { v1: T1[K]; v2: T2[K]; }; } + + [K in keyof T1 & keyof T2]: { + v1: T1[K]; +>v1 : T1[K] + + v2: T2[K]; +>v2 : T2[K] + + }; +}): [T1, T2]; + +const result3 = fn3({ +>result3 : [{ a: string; b: boolean; }, { a: number; b: null; }] +>fn3({ a: { v1: "foo", v2: 100, }, b: { v1: true, v2: null, },}) : [{ a: string; b: boolean; }, { a: number; b: null; }] +>fn3 : (obj: { [K in keyof T1 & keyof T2]: { v1: T1[K]; v2: T2[K]; }; }) => [T1, T2] +>{ a: { v1: "foo", v2: 100, }, b: { v1: true, v2: null, },} : { a: { v1: string; v2: number; }; b: { v1: true; v2: null; }; } + + a: { +>a : { v1: string; v2: number; } +>{ v1: "foo", v2: 100, } : { v1: string; v2: number; } + + v1: "foo", +>v1 : string +>"foo" : "foo" + + v2: 100, +>v2 : number +>100 : 100 + + }, + b: { +>b : { v1: true; v2: null; } +>{ v1: true, v2: null, } : { v1: true; v2: null; } + + v1: true, +>v1 : true +>true : true + + v2: null, +>v2 : null + + }, +}); + +declare function fn4>(arg: { +>fn4 : >(arg: { [K in keyof T & keyof E]: { data: T[K]; onSuccess: (data: T[K]) => void; error: E[K]; onError: (data: E[K]) => void; }; }) => [T, E] +>arg : { [K in keyof T & keyof E]: { data: T[K]; onSuccess: (data: T[K]) => void; error: E[K]; onError: (data: E[K]) => void; }; } + + [K in keyof T & keyof E]: { + data: T[K]; +>data : T[K] + + onSuccess: (data: T[K]) => void; +>onSuccess : (data: T[K]) => void +>data : T[K] + + error: E[K]; +>error : E[K] + + onError: (data: E[K]) => void; +>onError : (data: E[K]) => void +>data : E[K] + + }; +}): [T, E]; + +const result4 = fn4({ +>result4 : [{ a: string; b: boolean; }, { a: 404; b: 500; }] +>fn4({ a: { data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, }, b: { data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, },}) : [{ a: string; b: boolean; }, { a: 404; b: 500; }] +>fn4 : >(arg: { [K in keyof T & keyof E]: { data: T[K]; onSuccess: (data: T[K]) => void; error: E[K]; onError: (data: E[K]) => void; }; }) => [T, E] +>{ a: { data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, }, b: { data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, },} : { a: { data: string; onSuccess: (dataArg: string) => void; error: 404; onError: (errorArg: 404) => void; }; b: { data: true; onSuccess: (dataArg: boolean) => void; error: 500; onError: (errorArg: 500) => void; }; } + + a: { +>a : { data: string; onSuccess: (dataArg: string) => void; error: 404; onError: (errorArg: 404) => void; } +>{ data: "foo", onSuccess: (dataArg) => { dataArg; }, error: 404, onError: (errorArg) => { errorArg; }, } : { data: string; onSuccess: (dataArg: string) => void; error: 404; onError: (errorArg: 404) => void; } + + data: "foo", +>data : string +>"foo" : "foo" + + onSuccess: (dataArg) => { +>onSuccess : (dataArg: string) => void +>(dataArg) => { dataArg; } : (dataArg: string) => void +>dataArg : string + + dataArg; +>dataArg : string + + }, + error: 404, +>error : 404 +>404 : 404 + + onError: (errorArg) => { +>onError : (errorArg: 404) => void +>(errorArg) => { errorArg; } : (errorArg: 404) => void +>errorArg : 404 + + errorArg; +>errorArg : 404 + + }, + }, + b: { +>b : { data: true; onSuccess: (dataArg: boolean) => void; error: 500; onError: (errorArg: 500) => void; } +>{ data: true, onSuccess: (dataArg) => { dataArg; }, error: 500, onError: (errorArg) => { errorArg; }, } : { data: true; onSuccess: (dataArg: boolean) => void; error: 500; onError: (errorArg: 500) => void; } + + data: true, +>data : true +>true : true + + onSuccess: (dataArg) => { +>onSuccess : (dataArg: boolean) => void +>(dataArg) => { dataArg; } : (dataArg: boolean) => void +>dataArg : boolean + + dataArg; +>dataArg : boolean + + }, + error: 500, +>error : 500 +>500 : 500 + + onError: (errorArg) => { +>onError : (errorArg: 500) => void +>(errorArg) => { errorArg; } : (errorArg: 500) => void +>errorArg : 500 + + errorArg; +>errorArg : 500 + + }, + }, +}); + diff --git a/tests/cases/compiler/reverseMappedTypeLimitedConstraint.ts b/tests/cases/compiler/reverseMappedTypeLimitedConstraint.ts deleted file mode 100644 index 7618ae65046a9..0000000000000 --- a/tests/cases/compiler/reverseMappedTypeLimitedConstraint.ts +++ /dev/null @@ -1,15 +0,0 @@ -type XNumber_ = { x: number } - -declare function foo_(props: {[K in keyof T & keyof XNumber_]: T[K]}): T; - -foo_({x: 1, y: 'foo'}); - -// ----------------------------------------------------------------------------------------- - -const checkType_ = () => (value: { [K in keyof U & keyof T]: U[K] }) => value; - -const checked_ = checkType_<{x: number, y: string}>()({ - x: 1 as number, - y: "y", - z: "z", -}); \ No newline at end of file diff --git a/tests/cases/compiler/reverseMappedTypeIntersectionConstraint.ts b/tests/cases/compiler/reverseMappedTypeLimitedConstraintWithIntersection1.ts similarity index 69% rename from tests/cases/compiler/reverseMappedTypeIntersectionConstraint.ts rename to tests/cases/compiler/reverseMappedTypeLimitedConstraintWithIntersection1.ts index e565549791177..80315d98f0aa9 100644 --- a/tests/cases/compiler/reverseMappedTypeIntersectionConstraint.ts +++ b/tests/cases/compiler/reverseMappedTypeLimitedConstraintWithIntersection1.ts @@ -1,14 +1,11 @@ // @strict: true +// @lib: esnext type StateConfig = { entry?: TAction states?: Record>; }; -type StateSchema = { - states?: Record; -}; - declare function createMachine< TConfig extends StateConfig, TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string, @@ -45,8 +42,6 @@ const checked = checkType<{x: number, y: string}>()({ z: "z", // undesirable property z is *not* allowed }); -checked; - // ----------------------------------------------------------------------------------------- interface Stuff { @@ -62,7 +57,7 @@ function doStuffWithStuff(s: { [K in keyof T & keyof Stuff]: T[ } } -doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) +const stuff1 = doStuffWithStuff({ field: 1, anotherField: 'a', extra: 123 }) function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff]: T[K] }[]): T[] { if(Math.random() > 0.5) { @@ -72,7 +67,7 @@ function doStuffWithStuffArr(arr: { [K in keyof T & keyof Stuff } } -doStuffWithStuffArr([ +const stuff2 = doStuffWithStuffArr([ { field: 1, anotherField: 'a', extra: 123 }, ]) @@ -80,26 +75,26 @@ doStuffWithStuffArr([ type XNumber = { x: number } -declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): void; +declare function foo(props: {[K in keyof T & keyof XNumber]: T[K]}): T; function bar(props: {x: number, y: string}) { return foo(props); // no error because lack of excess property check by design } -foo({x: 1, y: 'foo'}); +const foo1 = foo({x: 1, y: 'foo'}); -foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design +const foo2 = foo({...{x: 1, y: 'foo'}}); // no error because lack of excess property check by design // ----------------------------------------------------------------------------------------- type NoErrWithOptProps = { x: number, y?: string } -declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): void; +declare function baz(props: {[K in keyof T & keyof NoErrWithOptProps]: T[K]}): T; -baz({x: 1}); -baz({x: 1, z: 123}); -baz({x: 1, y: 'foo'}); -baz({x: 1, y: 'foo', z: 123}); +const baz1 = baz({x: 1}); +const baz2 = baz({x: 1, z: 123}); +const baz3 = baz({x: 1, y: 'foo'}); +const baz4 = baz({x: 1, y: 'foo', z: 123}); // ----------------------------------------------------------------------------------------- @@ -118,8 +113,6 @@ const wnp = withNestedProp({prop: 'foo', nested: { prop: 'bar' }, extra: 10 }); type IsLiteralString = string extends T ? false : true; -type DeepWritable = T extends Function ? T : { -readonly [K in keyof T]: DeepWritable } - interface ProvidedActor { src: string; logic: () => Promise; @@ -142,10 +135,6 @@ interface MachineConfig { }; } -type NoExtra = { - [K in keyof T]: K extends keyof MachineConfig ? T[K] : never -} - declare function createXMachine< const TConfig extends MachineConfig, TActor extends ProvidedActor = TConfig extends { types: { actors: ProvidedActor} } ? TConfig["types"]["actors"] : ProvidedActor, @@ -172,3 +161,72 @@ const config2 = createXMachine({ }, extra: 10 }); + +declare function fn1>(obj: { + [K in keyof T & "a"]: T[K]; +}): T; +const obj1 = { + a: 42, + b: true, +}; +const result1 = fn1(obj1); + +declare function fn2>(obj: { + [K in (keyof T & "a") | "b"]: T[K]; +}): T; +const obj2 = { + a: 42, + b: 100, + c: true, +}; +const result2 = fn2(obj2); + +declare function fn3(obj: { + [K in keyof T1 & keyof T2]: { + v1: T1[K]; + v2: T2[K]; + }; +}): [T1, T2]; + +const result3 = fn3({ + a: { + v1: "foo", + v2: 100, + }, + b: { + v1: true, + v2: null, + }, +}); + +declare function fn4>(arg: { + [K in keyof T & keyof E]: { + data: T[K]; + onSuccess: (data: T[K]) => void; + error: E[K]; + onError: (data: E[K]) => void; + }; +}): [T, E]; + +const result4 = fn4({ + a: { + data: "foo", + onSuccess: (dataArg) => { + dataArg; + }, + error: 404, + onError: (errorArg) => { + errorArg; + }, + }, + b: { + data: true, + onSuccess: (dataArg) => { + dataArg; + }, + error: 500, + onError: (errorArg) => { + errorArg; + }, + }, +});