How to define Typescript type as a dictionary of strings but with one numeric “id” property

There is no specific type in TypeScript that corresponds to your desired structure. String index signatures must apply to every property, even the manually declared ones like id. What you’re looking for is something like a “rest index signature” or a “default property type”, and there is an open suggestion in GitHub asking for this: … Read more

Transform union type to intersection type

You want union to intersection? Distributive conditional types and inference from conditional types can do that. (Don’t think it’s possible to do intersection-to-union though, sorry) Here’s the evil magic: type UnionToIntersection<U> = (U extends any ? (k: U)=>void : never) extends ((k: infer I)=>void) ? I : never That distributes the union U and repackages … Read more