Skip to content

Omit keyof any #63266

@fudom

Description

@fudom

🔎 Search Terms

Omit

🕗 Version & Regression Information

typescript ~5.5

💻 Code

options?: Omit<PopoverOptions, 'component' | 'componentProps' | 'event'> = {}
// But freestyle, because `any` type.

🙁 Actual behavior

type Pick<T, K extends keyof T> = { [P in K]: T[P]; };
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

Why keyof any and not key of T like in Pick?

🙂 Expected behavior

type Pick<T, K extends keyof T> = { [P in K]: T[P]; };
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

Why not using keyof T like in Pick? I mean, what type of keys should be omitted if not from passed object? Any reason for this?

Workaround (might work, not tested):

type StrictOmit<T, K extends keyof T> = Omit<T, K>;

Or invert by WeakOmit<T, K extends keyof any> if Omit<T, K extends keyof T>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions