Skip to content

Suggest to wrap data parameter type in setUserSession function with SubSet #479

@CorrM

Description

@CorrM

export async function setUserSession(event: H3Event, data: OmitWithIndexSignature<UserSession, 'id'>, config?: Partial<SessionConfig>): Promise<UserSession> {

Suggest to wrap data parameter type in setUserSession function with SubSet(maybe DeepPartial)

// Credits: https://norday.tech/posts/2021/typescript-partial/
type Subset<K> = {
    [attr in keyof K]?: K[attr] extends object
        ? Subset<K[attr]>
        : K[attr] extends object | null
        ? Subset<K[attr]> | null
        : K[attr] extends object | null | undefined
        ? Subset<K[attr]> | null | undefined
        : K[attr];
};

that will suppress that error:

// Type '{ foo: string; }' is missing the following properties from type 'User': id, name, email, image, and 3
await setUserSession(event, {
  user: {
    foo: normalizedAddress,
  },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions