【问题标题】:How to fix typescript error (Readonly<{}> & Readonly<{ children?: ReactNode; }>)?如何修复打字稿错误(Readonly<{}> & Readonly<{ children?: ReactNode; }>)?
【发布时间】:2020-09-20 01:52:34
【问题描述】:

如何修复打字稿错误?

我从工作 git 存储库中克隆了应用程序,启动并收到错误:

“只读” 和只读'。 TS2339

    <div className="login-block__form__head__text">
      {// @ts-ignore
      this.props.language === 'EN'// err
        ? 'Login'
        : 'LOGIN'}{' '}
    </div>

不幸的是,我不知道打字稿,所以我不得不寻求帮助。

【问题讨论】:

  • 什么存储库?

标签: reactjs typescript


【解决方案1】:

在这种情况下,您没有定义道具类型。

interface PropType {
  language: string,
}

export default class ComponentName extends React.Component<PropType> {
...
}

如果您想了解有关 typescript 的更多信息,以下链接会有所帮助。

【讨论】:

    猜你喜欢
    • 2020-11-07
    • 2019-12-11
    • 2020-01-24
    • 2020-11-29
    • 2018-10-11
    • 2018-10-14
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多