gpt4 book ai didi

typescript - 汇总 typescript 装饰器支持

转载 作者:行者123 更新时间:2023-12-04 13:41:08 32 4
gpt4 key购买 nike

我收到以下错误消息:

Error: Parse Error: Line 29: Unexpected token ILLEGAL



对应的代码行是 mobx 观察者装饰器:
@observer
class Wrapper extends Component<IProps> {

我有以下 rollup.config.js:
import typescript from 'rollup-plugin-typescript2'
import jsx from 'rollup-plugin-jsx'
import pkg from './package.json'
export default {
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
},
{
file: pkg.module,
format: 'es',
},
],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
plugins: [
jsx( {factory: 'React.createElement'} ),
typescript({
typescript: require('typescript'),
}),
],
}

我的 tsconfig.json:
{
"compilerOptions": {
"declaration": true,
"declarationDir": "./dist",
"module": "es6",
"experimentalDecorators": true,
"outDir": "./dist",
"target": "es5",
"jsx": "react",
"types": ["reflect-metadata", "node"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": false,
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"importHelpers": true,
"sourceMap": true,
"noImplicitReturns": false,
"noImplicitThis": false,
"noImplicitAny": false,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": false,
"noUnusedLocals": true
},
"include": [
"src/**/*"
],
"exclude": ["node_modules"]
}

正如文档所说, https://github.com/ezolenko/rollup-plugin-typescript2插件应该从我的 tsconfig.json 文件中获取所有选项,还有“experimentalDecorators”:true,但似乎不起作用。

最佳答案

不是 100% 确定这适用,因为我的错误略有不同( Error: Unexpected character '@' )。

但是通过汇总与 TypeScript 装饰器一起解决的问题是删除 outDir选项来自 tsconfig.json .

关于typescript - 汇总 typescript 装饰器支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56804072/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com