What are all the index.ts used for?

前端 未结 3 1327
死守一世寂寞
死守一世寂寞 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:52

    index.ts is similar index.js in nodejs or index.html is web site hosting.

    So when you say import {} from 'directory_name' it will look for index.ts inside the specified directory and import whatever is exported there.

    For example if you have calculator/index.ts as

    export function add() {...}
    export function multiply() {...}
    

    You can do

    import { add, multiply } from './calculator';
    

提交回复
热议问题