在过去的几个小时里,我一直在努力解决这个问题,而我似乎无法在互联网上找到任何可以清楚解释这个,据说是简单概念的东西.
我目前正在研究一个使用Webpack2和TypeScript的ReactJS项目.除了一件事之外,一切都完美无缺 - 我无法找到一种方法将我自己编写的界面移动到单独的文件中,以便它们对整个应用程序可见.
出于原型设计的目的,我最初在使用它们的文件中定义了接口,但最终我开始添加一些在多个类中需要的东西,并且当所有问题都开始时.无论我对我做了什么改变tsconfig.json,无论我把文件放在哪里,我的IDE和Webpack都抱怨无法找到名字(Could not find name 'IMyInterface').
这是我当前的tsconfig.json文件:
{
"compilerOptions": {
"baseUrl": "src",
"outDir": "build/dist",
"module": "commonjs",
"target": "es5",
"lib": [
"es6",
"dom"
],
"typeRoots": [
"./node_modules/@types",
"./typings"
],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true
},
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts"
],
"types": [
"typePatches"
]
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我tsconfig.json位于项目目录的根目录中,所有源都在 …