【问题标题】:Why typescript emits error compilation in react-script with keywords?为什么 typescript 在带有关键字的 react-script 中发出错误编译?
【发布时间】:2021-04-03 16:30:10
【问题描述】:

我对带有 react-scripts 的 typescript 有非常奇怪的问题

 Line 5:16:  Parsing error: Unexpected token

  3 |  class AutoUpdateBase<TBinding> implements IAutoUpdate<TBinding>{
  4 |
> 5 |      protected binding?: (arg: TBinding) => void;
    |                ^
  6 |
  7 |      resolveValue(): TBinding{ throw new Error('Not implements'); };
  8 |      reciveValue(value: TBinding): void{ throw new Error('Not implements'); };

...这可能会发生??

【问题讨论】:

    标签: reactjs typescript compiler-errors keyword react-scripts


    【解决方案1】:

    几乎可以肯定,您的环境没有正确设置为加载或转换 typescript,并且您看到的错误是由于它试图将 typescript 解释为 javascript(没有 protected 关键字)。

    但是,由于您的问题几乎不包含回答它所需的任何上下文,例如正在运行什么构建命令导致错误、在什么工具中、在什么反应托管环境中,几乎不可能提供更具体的指导.

    【讨论】:

    • 感谢您这么快的回复,我只使用了带有 react-scripts 的环境,比如说开发部分,命令是 npm start,它又调用了 * start * of` react- scripts`,也许我在 tsconfig.ts 中有一些不好的地方,因为 vscode IDE 没有发出任何关于该错误的问题
    • 可能打字稿没问题(因此 VSCode 不会抱怨),但是任何试图将打字稿文件作为 javascript 运行的东西都是不好的。我们看不到您的任何配置或运行方式,因此无法多说。
    • 这是repo github.com/oliver021/post-io/tree/develop,这里有所有配置
    • 从存储库安装时出现问题github.com/oliver021/post-io/issues/1
    猜你喜欢
    • 1970-01-01
    • 2021-04-21
    • 2019-03-02
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2021-04-18
    相关资源
    最近更新 更多