For example, inside you component you want to import a file from two up directory:
import store from '../../store'
This becomes a little bit problematic because the component can be really nested.
To solve this problem, we can define "paths" in tsconfig.json:
{ ... "compilerOptions": { "baseUrl": ".", "paths": { "store": ["src/store.ts"] }, ... "target": "es5" } }
Now for each component, we can just use:
import store from 'store'
本文介绍了一种解决TypeScript项目中组件深嵌套导致的相对路径导入问题的方法。通过在tsconfig.json文件中配置baseUrl和paths选项,可以简化文件导入路径,提高代码的可读性和可维护性。
204

被折叠的 条评论
为什么被折叠?



