Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 键入脚本和节点并导入_Node.js_Import_Typescript - Fatal编程技术网

Node.js 键入脚本和节点并导入

Node.js 键入脚本和节点并导入,node.js,import,typescript,Node.js,Import,Typescript,我正在尝试将TypeScript与TypeScript require一起在Node.js中使用。所以我想: // index.js, line 1. require("typescript-require")({ "nodeLib": true }); 因此我加载了Main.ts文件。喜欢它: // index.js, line 2. require("Main.ts").init(); 所以我有一个字典界面: // Main.ts, line 8. interface Dictionar

我正在尝试将TypeScript
TypeScript require
一起在Node.js中使用。所以我想:

// index.js, line 1.
require("typescript-require")({ "nodeLib": true });
因此我加载了
Main.ts
文件。喜欢它:

// index.js, line 2.
require("Main.ts").init();
所以我有一个
字典
界面:

// Main.ts, line 8.
interface Dictionary<TValue> {
    [index: string]: TValue;
}
但是我喜欢将
字典
Main
分开。允许其他文件使用此界面而不复制它我的问题就从这里开始。我不知道如何才能做到这一点。我尝试了很多方法,比如使用
引用
导入要求
,我收到了来自所有方法的错误

/// Without any import, I get an obvious error; or,
/// <reference path="Dictionary" />; or,
/// <reference path="Dictionary.ts" />; or,
/// <reference path="./Dictionary.ts" />; or,
import Dictionary = require("Dictionary");
>> Main.ts(6,18): error TS2304: Cannot find name 'Dictionary'.

import Dictionary = require("Dictionary.ts");
>> Main.ts(1,29): error TS2304: Cannot find name 'Dictionary'.
>> Main.ts(6,18): error TS2315: Type 'any' is not generic.
///没有任何导入,我得到一个明显的错误;或
/// ; 或
/// ; 或
/// ; 或
导入字典=需要(“字典”);
>>ts(6,18):错误TS2304:找不到名称“Dictionary”。
导入字典=需要(“Dictionary.ts”);
>>ts(1,29):错误TS2304:找不到名称“Dictionary”。
>>ts(6,18):错误TS2315:类型“any”不是泛型。

在所有情况下,
Main.ts
似乎都没有正确地包含该文件,因此我无法重用它。所以我忘了什么?

在我发布之前,我找到了解决方案。我正在尝试导出文件
Dictionary.ts上的接口,喜欢它:

export interface ... { ... }
但是我需要导出它。比如:

interface Name { ... }
export = Name;
interface Name { ... }
export = Name;