Derive Union of String Literal Types with Lookup Types

PHOTO EMBED

Wed Feb 02 2022 23:51:53 GMT+0000 (Coordinated Universal Time)

Saved by @antistructure #typescript

type KeysOfType<T, K> = { [P in keyof T]: T[P] extends K ? P : never }[keyof T];

type PostStringKeys = KeysOfType<Post, string>;
type PostNumberKeys = KeysOfType<Post, number>;
content_copyCOPY

https://dev.to/remshams/derive-union-of-string-literal-types-with-lookup-types-in-typescript-1kkf