通常、型定義はimportで読み込みますが、importせずにどこでも使いたい場合の設定メモです。
├── index.ts ├── tsconfig.json └── types └── User └── index.d.ts
types/User/index.d.ts で declare を使って型定義を行います。
declare type User = { id: string name: string email: string }
tsconfigでは、”types” を使って読み込みを行います。
"types": ["./types/User"],
これで、importせずにどこでもUserを利用可能になります。
const hello = (user: User) => { console.log(`Hello ${user.name}`); } hello({id: '1', name: 'Taro', email: 'hoge'})