Add diff type for typescript
sanex3339 opened this issue · 6 comments
sanex3339 commented
Now we can add diff
type to the TS section
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];
niieani commented
Can you link to the source of this? Thanks.
Also, PR's are welcome.
pelotom commented
It's not quite the same since Diff
subtracts unions of literals, whereas $Diff
subtracts objects. Omit
, based on Diff
, is closer:
type Omit<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]};
Omit<{ a: string, b: number }, 'a'> // = { b: number }
n9 commented
niieani commented
I'd appreciate a PR to the README. As long as there are no caveats with Omit (I remember initially there used to be), we can add it.
niieani commented
TS 2.8 now has official support. I'll close this issue and make an umbrella issue for 2.8.