utils/src/types.ts
ztimson cdcaeda67c
All checks were successful
Build / Build NPM Project (push) Successful in 40s
Build / Tag Version (push) Successful in 8s
Build / Publish Documentation (push) Successful in 35s
+ Added writable
2025-05-12 18:00:12 -04:00

28 lines
532 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 typeKeys<T extends object>() {
return Object.keys(<T>{}) as Array<keyof T>;
}
/**
* Mark all properties as writable
*/
export type Writable<T> = {
-readonly [P in keyof T]: T[P]
};