我有一个带有枚举的typescript组件:
const enum blah {
one = "one",
two = "two"
}
如果没有typescript枚举,typscript组件将正确编译和显示,但如果代码中有枚举,则不会。
如何使故事书理解打字脚本中的枚举?
Storybook正在使用Babel进行Typescript传输。
使用ts加载程序
自定义故事书webpack配置并使用ts-loader
而不是Babel为我做了这件事。我的项目的其余部分也使用ts-loader
进行设置,所以你可能需要研究如何使用它来设置项目。
// .storybook/main.js
module.exports = {
// ... other configuration here
// Customize the webpack configuration
webpackFinal: async(config) => {
// We want to use ts-loader for tsx files
config.module.rules.push({
test: /.tsx?$/,
use: 'ts-loader',
});
return config;
}
};
使用Babel
我没能使用Babel,但关于这个问题的一些评论建议使用babel-preset-const-enum
。
来源
- 故事书Webpack配置
- 帮助我弄清楚的问题