如何在项目内声明公共的 TS 类型定义
-
在项目仓库中创建
types/index.ts文件。 -
在这个文件中导出声明的接口:
export interface MyType { propertyA: string propertyB?: string propertyC?: any propertyD?: any } -
在业务代码中可以引用这个类型声明:
import { MyType } from '../types' const obj: MyType = {/* ... */}
在项目仓库中创建 types/index.ts 文件。
在这个文件中导出声明的接口:
export interface MyType {
propertyA: string
propertyB?: string
propertyC?: any
propertyD?: any
}
在业务代码中可以引用这个类型声明:
import { MyType } from '../types'
const obj: MyType = {/* ... */}