Skip to content

Commit 3cf7cea

Browse files
committed
Add extra test case
1 parent bfdd0d9 commit 3cf7cea

4 files changed

Lines changed: 125 additions & 1 deletion

tests/baselines/reference/declarationEmitMappedTypePreservesTypeParameterConstraint.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,34 @@ export const buildSchema = <V extends string>(
4343
): objectOutputType<{
4444
version: ZodLiteral<V>;
4545
}> => ({} as any);
46+
47+
// repro from https://github.com/microsoft/TypeScript/issues/55049
48+
49+
type evaluate<t> = { [k in keyof t]: t[k] } & unknown
50+
51+
export type entryOf<o> = evaluate<
52+
{ [k in keyof o]-?: [k, o[k] & ({} | null)] }[o extends readonly unknown[]
53+
? keyof o & number
54+
: keyof o]
55+
>
56+
57+
export type entriesOf<o extends object> = evaluate<entryOf<o>[]>
58+
59+
export const entriesOf = <o extends object>(o: o) =>
60+
Object.entries(o) as entriesOf<o>
4661

4762

4863
//// [declarationEmitMappedTypePreservesTypeParameterConstraint.js]
4964
"use strict";
5065
// repro from https://github.com/microsoft/TypeScript/issues/54560
5166
Object.defineProperty(exports, "__esModule", { value: true });
52-
exports.buildSchema = void 0;
67+
exports.entriesOf = exports.buildSchema = void 0;
5368
var buildSchema = function (version) { return ({}); };
5469
exports.buildSchema = buildSchema;
70+
var entriesOf = function (o) {
71+
return Object.entries(o);
72+
};
73+
exports.entriesOf = entriesOf;
5574

5675

5776
//// [declarationEmitMappedTypePreservesTypeParameterConstraint.d.ts]
@@ -79,4 +98,12 @@ export declare type ZodRawShape = {
7998
export declare const buildSchema: <V extends string>(version: V) => addQuestionMarks<baseObjectOutputType<{
8099
version: ZodLiteral<V>;
81100
}>, undefined extends V ? never : "version"> extends infer T ? { [K in keyof T]: T[K]; } : never;
101+
type evaluate<t> = {
102+
[k in keyof t]: t[k];
103+
} & unknown;
104+
export type entryOf<o> = evaluate<{
105+
[k in keyof o]-?: [k, o[k] & ({} | null)];
106+
}[o extends readonly unknown[] ? keyof o & number : keyof o]>;
107+
export type entriesOf<o extends object> = evaluate<entryOf<o>[]>;
108+
export declare const entriesOf: <o extends object>(o: o) => ({ [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o] extends infer T ? { [K in keyof T]: T[K]; } : never)[];
82109
export {};

tests/baselines/reference/declarationEmitMappedTypePreservesTypeParameterConstraint.symbols

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,55 @@ export const buildSchema = <V extends string>(
127127

128128
}> => ({} as any);
129129

130+
// repro from https://github.com/microsoft/TypeScript/issues/55049
131+
132+
type evaluate<t> = { [k in keyof t]: t[k] } & unknown
133+
>evaluate : Symbol(evaluate, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 41, 18))
134+
>t : Symbol(t, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 45, 14))
135+
>k : Symbol(k, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 45, 22))
136+
>t : Symbol(t, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 45, 14))
137+
>t : Symbol(t, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 45, 14))
138+
>k : Symbol(k, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 45, 22))
139+
140+
export type entryOf<o> = evaluate<
141+
>entryOf : Symbol(entryOf, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 45, 53))
142+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 47, 20))
143+
>evaluate : Symbol(evaluate, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 41, 18))
144+
145+
{ [k in keyof o]-?: [k, o[k] & ({} | null)] }[o extends readonly unknown[]
146+
>k : Symbol(k, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 48, 7))
147+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 47, 20))
148+
>k : Symbol(k, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 48, 7))
149+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 47, 20))
150+
>k : Symbol(k, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 48, 7))
151+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 47, 20))
152+
153+
? keyof o & number
154+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 47, 20))
155+
156+
: keyof o]
157+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 47, 20))
158+
159+
>
160+
161+
export type entriesOf<o extends object> = evaluate<entryOf<o>[]>
162+
>entriesOf : Symbol(entriesOf, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 51, 1), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 12))
163+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 53, 22))
164+
>evaluate : Symbol(evaluate, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 41, 18))
165+
>entryOf : Symbol(entryOf, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 45, 53))
166+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 53, 22))
167+
168+
export const entriesOf = <o extends object>(o: o) =>
169+
>entriesOf : Symbol(entriesOf, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 51, 1), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 12))
170+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 26), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 44))
171+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 26), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 44))
172+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 26), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 44))
173+
174+
Object.entries(o) as entriesOf<o>
175+
>Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
176+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
177+
>entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --))
178+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 26), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 44))
179+
>entriesOf : Symbol(entriesOf, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 51, 1), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 12))
180+
>o : Symbol(o, Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 26), Decl(declarationEmitMappedTypePreservesTypeParameterConstraint.ts, 55, 44))
181+

tests/baselines/reference/declarationEmitMappedTypePreservesTypeParameterConstraint.types

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,32 @@ export const buildSchema = <V extends string>(
7575
>{} as any : any
7676
>{} : {}
7777

78+
// repro from https://github.com/microsoft/TypeScript/issues/55049
79+
80+
type evaluate<t> = { [k in keyof t]: t[k] } & unknown
81+
>evaluate : { [k in keyof t]: t[k]; }
82+
83+
export type entryOf<o> = evaluate<
84+
>entryOf : { [k in keyof { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o]]: { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o][k]; }
85+
86+
{ [k in keyof o]-?: [k, o[k] & ({} | null)] }[o extends readonly unknown[]
87+
? keyof o & number
88+
: keyof o]
89+
>
90+
91+
export type entriesOf<o extends object> = evaluate<entryOf<o>[]>
92+
>entriesOf : { [k in keyof { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o]]: { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o][k]; }[]
93+
94+
export const entriesOf = <o extends object>(o: o) =>
95+
>entriesOf : <o extends object>(o: o) => { [k in keyof { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o]]: { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o][k]; }[]
96+
><o extends object>(o: o) => Object.entries(o) as entriesOf<o> : <o extends object>(o: o) => { [k in keyof { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o]]: { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o][k]; }[]
97+
>o : o
98+
99+
Object.entries(o) as entriesOf<o>
100+
>Object.entries(o) as entriesOf<o> : { [k in keyof { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o]]: { [k in keyof o]-?: [k, o[k] & ({} | null)]; }[o extends readonly unknown[] ? keyof o & number : keyof o][k]; }[]
101+
>Object.entries(o) : [string, any][]
102+
>Object.entries : { <T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][]; (o: {}): [string, any][]; }
103+
>Object : ObjectConstructor
104+
>entries : { <T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][]; (o: {}): [string, any][]; }
105+
>o : o
106+

tests/cases/compiler/declarationEmitMappedTypePreservesTypeParameterConstraint.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @strict: true
22
// @declaration: true
3+
// @lib: esnext
34

45
// repro from https://github.com/microsoft/TypeScript/issues/54560
56

@@ -43,3 +44,18 @@ export const buildSchema = <V extends string>(
4344
): objectOutputType<{
4445
version: ZodLiteral<V>;
4546
}> => ({} as any);
47+
48+
// repro from https://github.com/microsoft/TypeScript/issues/55049
49+
50+
type evaluate<t> = { [k in keyof t]: t[k] } & unknown
51+
52+
export type entryOf<o> = evaluate<
53+
{ [k in keyof o]-?: [k, o[k] & ({} | null)] }[o extends readonly unknown[]
54+
? keyof o & number
55+
: keyof o]
56+
>
57+
58+
export type entriesOf<o extends object> = evaluate<entryOf<o>[]>
59+
60+
export const entriesOf = <o extends object>(o: o) =>
61+
Object.entries(o) as entriesOf<o>

0 commit comments

Comments
 (0)