Skip to content

Commit

Permalink
Ensure Record into Object for known Enum keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 2, 2023
1 parent ce1ace5 commit 2bba92a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/typebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ export interface TPromise<T extends TSchema = TSchema> extends TSchema {
export type TRecordFromUnionLiteralString<K extends TLiteralString, T extends TSchema> = { [_ in K['const']]: T }
export type TRecordFromUnionLiteralNumber<K extends TLiteralNumber, T extends TSchema> = { [_ in K['const']]: T }
// prettier-ignore
export type TRecordFromEnumKey<K extends TEnum, T extends TSchema> = Ensure<TRecord<K, T>>
export type TRecordFromEnumKey<K extends Record<string, string | number>, T extends TSchema> = Ensure<TObject<{ [_ in K[keyof K]]: T }>>
// prettier-ignore
export type TRecordFromUnionRest<K extends TSchema[], T extends TSchema> = K extends [infer L, ...infer R] ? (
L extends TUnion<infer S> ? TRecordFromUnionRest<S, T> & TRecordFromUnionRest<AssertRest<R>, T> :
Expand All @@ -671,7 +671,7 @@ export type TRecordFromNumberKey<K extends TNumber, T extends TSchema> = Ensure<
export type TRecordFromIntegerKey<K extends TInteger, T extends TSchema> = Ensure<TRecord<K, T>>
// prettier-ignore
export type TRecordResolve<K extends TSchema, T extends TSchema> =
K extends TEnum<infer _> ? TRecordFromEnumKey<K, T> : // Enum before Union (intercept Hint)
K extends TEnum<infer S> ? TRecordFromEnumKey<S, T> : // Enum before Union (intercept Hint)
K extends TUnion<infer S> ? TRecordFromUnion<S, T> :
K extends TTemplateLiteral ? TRecordFromTemplateLiteralKey<K, T> :
K extends TLiteralString ? TRecordFromLiteralStringKey<K, T> :
Expand Down

0 comments on commit 2bba92a

Please sign in to comment.