【发布时间】:2022-08-03 22:11:23
【问题描述】:
在我的 ReactJS 应用程序中,我曾经使用 labels.js 对象在语言之间切换:
export const labelsENG = {
navSeries: \'shows\',
navHome: \'home\',
navVideo: \'video\',
navGames: \'games\',
navCurrent: \'current\',
navCatchUp: \'shame pile\',
navCommingSoon: \'comming soon\',
navFinished: \'finished\',
formModalHeader: \'Add new Poster\',
modalNoWiki: \'No wiki for \',
modalCloseButton: \'CLOSE MODAL\',
modalReleased: \'Relased \',
modalSeenAt: \'You seen it \',
itemPart: \'Part \',
itemSeason: \'Season \',
footerCopyRights: \'© 2022 Listownik by Kuba\',
footerHere: \'Footer here\',
error404: \'Error 404 Page Not Happy\',
errorDescribtion: `It\'s working anyway`,
posterText: \'Some text\',
shelfSeen: \'Seen\'
};
现在我正在尝试将该代码转换为 TypeScript。 有没有比分别为每个参数创建带有字符串的接口更有效或更优雅的方法来为该对象声明类型?
export interface LabelsInterface {
navSeries: string;
navHome: string;
navVideo: string;
navGames: string;
navCurrent: string;
navCatchUp: string;
navCommingSoon: string;
navFinished: string;
modalNoWiki: string;
modalCloseButton: string;
modalReleased: string;
modalSeenAt: string;
itemPart: string;
itemSeason: string;
footerCopyRights: string;
footerHere: string;
error404: string;
errorDescribtion: string;
posterText: string;
shelfSeen: string;
}
-
取决于您的目标是什么.. 如果您喜欢一种主语言,而其他语言遵循相同的结构,您可以这样做
export type LabelsInterface = typeof labelsENG
标签: reactjs typescript types label