Given this type alias:
export type RequestObject = {
user_id: number,
address: string,
user_type: number,
points: number,
};
I want an array of all its properties, e.g:
['user_id','address','user_type','points']
Is there any option to get this? I have googled but I can get it only for interface using following package
Typescript types only exist at compile time. They do not exist in the compiled javascript. Thus you cannot populate an array (a runtime entity) with compile-time data (such as the RequestObject
type alias), unless you do something complicated like the library you found.
RequestObject
.import { keys } from 'ts-transformer-keys';
export type RequestObject = {
user_id: number,
address: string,
user_type: number,
points: number,
}
interface IRequestObject extends RequestObject {}
const keysOfProps = keys<IRequestObject>();
console.log(keysOfProps); // ['user_id', 'address', 'user_type', 'points']