StrictOmit<T, K>
StrictOmit<
T,K> =Omit<T,K>
Like Omit<T, K> but enforces that K must be a key of T.
TypeScript's built-in Omit accepts any string as K, which can hide typos.
StrictOmit catches these errors at compile time.
Type Parametersโ
T: Tโ
The object type
K: K extends keyof Tโ
The keys to omit (must exist in T)
Sinceโ
2.0.0
Exampleโ
type User = { id: string; name: string; email: string };
type WithoutEmail = StrictOmit<User, "email">;
// = { id: string; name: string }
type Typo = StrictOmit<User, "emial">;
// โ Error: Type '"emial"' does not satisfy the constraint 'keyof User'