TypeScript Creating Object Field Names as Union Type Usages

In order to support Union Type, I used Conditional Type.

type ObjectFieldNames<T> = T extends any ? keyof T : never;
type ObjectFieldNames<T> = T extends { [P in infer A]: any } ? A : never;
type ObjectFieldNames<T> = T extends Record<infer K, any> ? K : never;

Leave a Reply

Your email address will not be published.