Skip to content

assign usage is confusing and types are broken. #409

@mctrafik

Description

@mctrafik

It's unexpected that assign isn't a straight mapping to Object.assign and the differences with it and lodash are very stark. Not modifying the original object is unexpected. It functions similar to lodash's object merge, but doesn't support multiple objects.

Lastly, the types are broken. I ran into this with FastifyHelmetOptions for both args and got a typescript error Type is infinite.
The merge of A and B is just A & B in lodash which makes sense. But radashi uses:

type Assign<TInitial extends object, TOverride extends object> = TInitial extends any ? TOverride extends any ? SimplifyMutable<Omit<TInitial, keyof TOverride> & Omit<TOverride, keyof TInitial> & (Pick<TInitial, keyof TInitial & keyof TOverride> extends infer TConflictInitial ? Pick<TOverride, keyof TInitial & keyof TOverride> extends infer TConflictOverride ? {
    [K in RequiredKeys<TConflictOverride>]: AssignDeep<TConflictInitial[K & keyof TConflictInitial], TConflictOverride[K]>;
} & {
    [K in RequiredKeys<TConflictInitial> & OptionalKeys<TConflictOverride>]: AssignDeep<TConflictInitial[K], TConflictOverride[K], true>;
} & {
    [K in OptionalKeys<TConflictInitial> & OptionalKeys<TConflictOverride>]?: AssignDeep<TConflictInitial[K], TConflictOverride[K], true>;
} : unknown : unknown)> : never : never;

which I imagine fails for any recursive type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting author replyThe author hasn't replied to a question, and it's been a few days

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions