utils/src/types.ts
ztimson 3896949fc1
Some checks failed
Build / Build NPM Project (push) Failing after 28s
Build / Tag Version (push) Has been skipped
Docs update
2024-09-22 02:38:13 -04:00

21 lines
425 B
TypeScript

/**
* Return keys on a type as an array of strings
*
* @example
* ```ts
* type Person = {
* firstName: string;
* lastName: string;
* age: number;
* }
*
* const keys = typeKeys<Person>();
* console.log(keys); // Output: ["firstName", "lastName", "age"]
* ```
*
* @return {Array<keyof T>} Available keys
*/
export function tyoeKeys<T extends object>() {
return Object.keys(<T>{}) as Array<keyof T>;
}