【发布时间】:2018-11-13 16:44:26
【问题描述】:
我正在尝试做一些与文档中的jquery path example 非常相似的事情,但是 TS 不断抛出 TS2307(webpack 编译良好):
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@client": [
"client",
],
"@suir": [
"../node_modules/semantic-ui-react/dist/commonjs", // not working
],
},
// …
},
"include": [
"*.d.ts",
"client/**/*",
"../node_modules/semantic-ui-react", // is this necessary?
],
将baseUrl 更改为"." 并更新includes 和paths 没有任何区别(@client 继续有效,@suir 继续无效)。
将"@suir" 更改为"@suir/" 或"@suir/*"(并将/* 附加到其值)也没有任何区别。
我这样做的原因是为了简化我的导入(我明确指定它们而不是从包中提取命名导出以减小我的供应商包大小 - 节省大约 1 MB):
import Button from 'semantic-ui-react/dist/commonjs/elements/Button'; // works
import Button from '@suir/elements/Button'; // not found
【问题讨论】:
-
只是想补充一下。对我来说,当我使用 tsconfig.json 中的
files属性时,paths停止工作。有什么解决办法吗?
标签: typescript alias tsconfig typescript2.9