TypeScript 是否能够从对象字面量推断出接口(interface)?就像下面这样:
export const theme = {
primaryColor: "#e9e9eb",
secondaryColor: "blue"
};
接口(interface)如下(AFAICT),TypeScript 迫使我为其创建一个单独的接口(interface),但我想自动派生。
export interface IThemeInterface {
primaryColor: string;
secondaryColor: string;
}
最佳答案
type IThemeInterface = typeof theme;
在这里做了正确的事情。
关于typescript - 从对象字面量派生 TypeScript 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56119073/