sindresorhus / type-fest

A collection of essential TypeScript types
Creative Commons Zero v1.0 Universal
13.64k stars 515 forks source link

`CamelCasedPropertiesDeep` doesn't handle `Tagged` type correctly #889

Closed Ghost-str closed 2 weeks ago

Ghost-str commented 1 month ago
type UUID = Tagged<string, "UUID">;

 type User = {
     user_id: UUID;
 }

type Article = {
    name: string;
    view_count: number;
    author: User;
}

type MyType = CamelCasedPropertiesDeep<Article>;

Got:

image

Expected:

UUID type

Upvote & Fund

Fund with Polar

Ghost-str commented 1 month ago

Possible solution:

export type CamelCasedPropertiesDeep<
    Value,
    Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true},
> = Value extends Function
    ? Value
    : Value extends UnknownArray
        ? CamelCasedPropertiesArrayDeep<Value>
        : Value extends Set<infer U>
            ? Set<CamelCasedPropertiesDeep<U, Options>>
            : Value extends Tag<any, any> 
                ? Value
                : {
                    [K in keyof Value as CamelCase<K, Options>]: CamelCasedPropertiesDeep<
                    Value[K],
                    Options
                    >;
                };