|
| 1 | +//// [tests/cases/compiler/declarationEmitMappedTypePreservesTypeParameterConstraint.ts] //// |
| 2 | + |
| 3 | +//// [declarationEmitMappedTypePreservesTypeParameterConstraint.ts] |
| 4 | +// repro from https://github.com/microsoft/TypeScript/issues/54560 |
| 5 | + |
| 6 | +declare type requiredKeys<T extends object> = { |
| 7 | + [k in keyof T]: undefined extends T[k] ? never : k; |
| 8 | +}[keyof T]; |
| 9 | + |
| 10 | +declare type addQuestionMarks< |
| 11 | + T extends object, |
| 12 | + R extends keyof T = requiredKeys<T> |
| 13 | +> = Pick<Required<T>, R> & Partial<T>; |
| 14 | + |
| 15 | +declare type identity<T> = T; |
| 16 | + |
| 17 | +declare type flatten<T> = identity<{ |
| 18 | + [k in keyof T]: T[k]; |
| 19 | +}>; |
| 20 | + |
| 21 | +export declare abstract class ZodType<Output = any> { |
| 22 | + readonly _output: Output; |
| 23 | +} |
| 24 | + |
| 25 | +export declare class ZodLiteral<T> extends ZodType<T> {} |
| 26 | + |
| 27 | +export declare type ZodTypeAny = ZodType<any>; |
| 28 | + |
| 29 | +export declare type baseObjectOutputType<Shape extends ZodRawShape> = { |
| 30 | + [k in keyof Shape]: Shape[k]["_output"]; |
| 31 | +}; |
| 32 | + |
| 33 | +export declare type objectOutputType<Shape extends ZodRawShape> = flatten< |
| 34 | + addQuestionMarks<baseObjectOutputType<Shape>> |
| 35 | +>; |
| 36 | + |
| 37 | +export declare type ZodRawShape = { |
| 38 | + [k: string]: ZodTypeAny; |
| 39 | +}; |
| 40 | + |
| 41 | +export const buildSchema = <V extends string>( |
| 42 | + version: V |
| 43 | +): objectOutputType<{ |
| 44 | + version: ZodLiteral<V>; |
| 45 | +}> => ({} 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> |
| 61 | + |
| 62 | + |
| 63 | +//// [declarationEmitMappedTypePreservesTypeParameterConstraint.js] |
| 64 | +"use strict"; |
| 65 | +// repro from https://github.com/microsoft/TypeScript/issues/54560 |
| 66 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 67 | +exports.entriesOf = exports.buildSchema = void 0; |
| 68 | +var buildSchema = function (version) { return ({}); }; |
| 69 | +exports.buildSchema = buildSchema; |
| 70 | +var entriesOf = function (o) { |
| 71 | + return Object.entries(o); |
| 72 | +}; |
| 73 | +exports.entriesOf = entriesOf; |
| 74 | + |
| 75 | + |
| 76 | +//// [declarationEmitMappedTypePreservesTypeParameterConstraint.d.ts] |
| 77 | +declare type requiredKeys<T extends object> = { |
| 78 | + [k in keyof T]: undefined extends T[k] ? never : k; |
| 79 | +}[keyof T]; |
| 80 | +declare type addQuestionMarks<T extends object, R extends keyof T = requiredKeys<T>> = Pick<Required<T>, R> & Partial<T>; |
| 81 | +declare type identity<T> = T; |
| 82 | +declare type flatten<T> = identity<{ |
| 83 | + [k in keyof T]: T[k]; |
| 84 | +}>; |
| 85 | +export declare abstract class ZodType<Output = any> { |
| 86 | + readonly _output: Output; |
| 87 | +} |
| 88 | +export declare class ZodLiteral<T> extends ZodType<T> { |
| 89 | +} |
| 90 | +export declare type ZodTypeAny = ZodType<any>; |
| 91 | +export declare type baseObjectOutputType<Shape extends ZodRawShape> = { |
| 92 | + [k in keyof Shape]: Shape[k]["_output"]; |
| 93 | +}; |
| 94 | +export declare type objectOutputType<Shape extends ZodRawShape> = flatten<addQuestionMarks<baseObjectOutputType<Shape>>>; |
| 95 | +export declare type ZodRawShape = { |
| 96 | + [k: string]: ZodTypeAny; |
| 97 | +}; |
| 98 | +export declare const buildSchema: <V extends string>(version: V) => objectOutputType<{ |
| 99 | + version: ZodLiteral<V>; |
| 100 | +}>; |
| 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) => entriesOf<o>; |
| 109 | +export {}; |
0 commit comments