logo
/
Indexでre-exportするのは使用側がすっきりするから
2023-03-16
TypeScript
二度手間なだけじゃ?と思ってたけど
  • 1.ts
export const func1 = () => {}
    1. ts
export const func2 = () => {}
のときに
  • app.ts
import { func1 } from 'path/to/1.ts'
import { func2 } from 'path/to/2.ts'
とするよりも
  • index.ts
export { func1 } from './1.ts'
export { func2 } from './2.ts'
のようにre-exportして
  • app.ts
import { func1, func2 } from 'path/to'
とすると情報がまとめられる
単純にindex.ts見れば使える関数(変数)を全部確認できるというのもあるけど