說實話,我很少知道實際發生了什麼。我試圖創建一個基於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