【typescript】全局可直接使用interface,无需import导入

549 阅读1分钟
  • 放置位置

type在文件中的位置

  • tsconfig.json配置

tsconfig中如何配置才能全局访问

  • 声明方式
// index.d.ts
declare interface IEditCardListItem { .... }

可以将type/interface的定义放到src/type下,需要将文件名称设置成xxx.d.tstsconfig.json中需要在include中将src/**/*.d.ts设置上这样就可以在其他地方直接使用而不需要import来进行对应的导入。

【总结】

  • tsconfig.jsoninclude中需要将interface或则type定义的文件包含
  • 定义类型的文件名称后缀是.d.ts
  • .d.ts文件中需要使用decalre来声明interface和type

【链接】

  • ts中的.d.ts和declare究竟是干什么的:链接