说实话,我很少知道实际发生了什么。我正在尝试根据显示的here创建一个声明文件 - 这是我以前从未做过的事情。
我有这些文件(由于工作规则而重命名和编辑):
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"
}
}
TypeScript可以很好地找到 project_one 声明文件。然而,它向我大喊import
来自它[ts] cannot find module 'project_one'.
说import
我想这个代码的错误不仅仅是我如何尝试从声明文件中导入东西,但是现在我是希望NSDate
行能够正常工作。
我误解了什么?
答案 0 :(得分:0)
自定义输入的位置应在tsconfig.json
{
"compilerOptions": {
"typeRoots": [
"./custom_typings",
"./node_modules/@types"
]
}
}
有关详细信息,请参阅tsconfig documentation。