Comment by chad_oliver
3 years ago
I believe this implements an exact object type in Typescript:
type Exactly<Candidate, Shape> = Shape & {
[key in keyof Candidate]: key extends keyof Shape ? Shape[key] : never;
};
Credit goes to Manan Tank: https://twitter.com/MananTank_/status/1677610004743086080
No, it doesn't.
It can't be represented in TypeScript type system.
You can't create utility type to have it.
Have a look at Flow docs [0] if you want to learn more.
His utility type works on diff between two provided types, this is something else.
Exact object type is a kind of type which doesn't allow extra, undeclared properties to be used for it to be satisfied.
You can't emulate it if it's not supported by type system.
The whole thing is implemented way better in Flow than TypeScript, ie. spreads map to how runtime treats them, this is also not something TypeScript can represent and Flow supports.
Also opaque types have first class support and many other things.
[0] https://flow.org/en/docs/types/objects/#exact-and-inexact-ob...