【问题标题】:create-react-app with typescript - how to put types in separate file使用打字稿创建反应应用程序 - 如何将类型放在单独的文件中
【发布时间】:2019-07-29 12:04:38
【问题描述】:

我正在使用带有打字稿的 CRA (create-react-app myapp --typescript)

我的App.tsx 中有一些我想在外部存储的打字稿内容,我已经尝试创建App.d.tsindex.d.tsmodule.d.ts,但都不起作用。

这是我正在使用的界面:

declare interface IArgs {
    home: string,
    away: string
}

我需要做什么才能在我的源文件可以共享的文件中声明我的所有 Typescript 内容?

【问题讨论】:

    标签: reactjs typescript create-react-app


    【解决方案1】:

    放入外部文件,例如。 interfaces/interfaces.ts:

    export interface IArgs {
        home: string,
        away: string
    }
    

    然后在您想使用它的App.tsx 中,通过import { IArgs } from 'interfaces/interfaces'; 导入它并根据您的需要使用它。

    【讨论】:

      猜你喜欢
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      • 2016-02-16
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      相关资源
      最近更新 更多