niieani/typescript-vs-flowtype

Add diff type for typescript

sanex3339 opened this issue · 6 comments

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];  

Can you link to the source of this? Thanks.
Also, PR's are welcome.

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 }

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.

TS 2.8 now has official support. I'll close this issue and make an umbrella issue for 2.8.