What are all the index.ts used for?

前端 未结 3 1329
死守一世寂寞
死守一世寂寞 2020-11-30 18:15

I\'ve been looking at a few seed projects and all the components seem to have a index.ts that exports * from that component. I can\'t find anywhere what it\'s actually used

3条回答
  •  鱼传尺愫
    2020-11-30 18:38

    index.ts help us to keep all related thing together and we don't need to worry about the source file name.

    We can import all thing by using source folder name.

    import { getName, getAnyThing } from './util';
    

    Here util is folder name not file name which has index.ts which re-export all four files.

    export * from './util1';
    export * from './util2';
    export * from './util3';
    export * from './util4';
    

提交回复
热议问题