说实话,我很少知道实际发生了什么。我试图创建一个基于here显示的声明文件 - 这是我以前从未做过的。ES6风格的输入从打字稿模块定义(module.d.ts)
我有这些文件(重命名和编辑因工作规则):
project_one
some_interface.ts
import SomeOtherInterface from "some_other_file";
interface ThisInterface
{
aMethodRequiring(aThing: SomeOtherInterface): void;
}
export default ThisInterface;
index.d.ts
export { default as ThisInterface } from "some_interface";
tsconfig.json
{
"compilerOptions": {
"baseUrl": "src",
"noImplicitAny": true,
"target": "es2015"
},
"exclude": [
"src/**/*.type.ts"
],
"include": [
"src/**/*.ts"
]
}
project_two
some_class.ts
/// <reference types="project_one" />
/*^This seems to be fine^*/
import SomethingInThisProject from "a_file_in_this_project";
import { ThisInterface } from "project_one"; // <=== This is the line that fails.
class ThatClass
{
private instanceOfThisInterface : ThisInterface;
constructor(saidInstance: ThisInterface)
{
this.instanceOfThisInterface = saidInstance;
}
// The useful stuff
}
export default ThatClass;
tsconfig.json
{
"compilerOptions": {
"baseUrl": "src",
"noImplicitAny": true,
"target": "es2015"
},
"exclude": [
"src/**/*.type.ts"
],
"include": [
"src/**/*.ts"
]
}
的package.json
{
"name": "project_two",
"version": "0.1.0",
"description": "A Second Project",
"main": "index.js",
"repository": "https://github.com/project/two",
"author": "Cyle Ven Dawson",
"license": "MIT",
"devDependencies": {
...
},
"dependencies": {
...
"project_one": "^0.5.0"
}
}
打字稿发现project_one声明文件就好了。然而,它大声对我说关于它的import
ing,说[ts] cannot find module 'project_one'.
我想象这个代码有更多的错误,而不仅仅是我如何尝试从声明文件中导入东西,但现在我期望让import
行工作。
我误解了什么?
你能告诉我们package.json吗?是否将'project_one'正确注册为'project_two'的依赖项? –
@ E_net4添加了package.json内容。如所示,将“project_one”设置为依赖项。 – dawsonc623