When dealing with a scenario where you want a pointfree omit
, you can achieve this:
type PlainObject<T> = {[key: string]: T}
const omit = <K extends string>(
name: K
) => <T, U extends PlainObject<T> & {
[P in K]: T
}>(
x: U,
): Partial<U> => {
throw new Error ('Yet to implement !')
}
Is there a way to use K
as an array of strings instead of just a string?
Perhaps something like this:
const omit = <K extends string[]>(
...names: K
) => <T, U extends PlainObject<T> & {
[P in K]: T // Type 'K' is not assignable to type 'string | number | symbol'
}>(
x: U,
): Partial<U> => {
throw new Error ('Yet to implement !')
}
The purpose here is to make the compiler flag any incorrect objects entered based on the keys passed:
omit('a', 'b')({b: 3, c: 4}) // => expect error
Thank you in advance
Seb