Working with tabular data in Typescript requires the use of interfaces to define column structures. To efficiently manipulate these structures, it is often necessary to retrieve the property names of these interfaces as an array of strings.
Since Typescript version 2.4, custom transformers provide a mechanism to extract keys from interfaces. Consider the following interface:
interface IMyTable {
id: number;
title: string;
createdAt: Date;
isDeleted: boolean;
}
To obtain the property names as an array:
import { keys } from 'ts-transformer-keys';
const IMyTable = keys();
console.log(IMyTable); // ["id", "title", "createdAt", "isDeleted"]
While custom transformers offer a convenient solution, they require the use of the Typescript transformation API rather than the ts command. This limitation can hinder their usability.
In scenarios where custom transformers are not feasible, alternative options include:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3