Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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_Typescript_Import_Webstorm - Fatal编程技术网

Node.js 节点类型脚本导入/导出机制

Node.js 节点类型脚本导入/导出机制,node.js,typescript,import,webstorm,Node.js,Typescript,Import,Webstorm,我对WebStorm中的TypeScript导入/导出机制有问题。 比如说,我有一个名为apiUtils.ts的文件: import apiUtils from "../bin/apiUtils"; const req = ''; const username = apiUtils.getUsername(req); 我还有另一个文件,它引用了apiUtils.ts: import apiUtils from "../bin/apiUtils"; const req = ''; const

我对WebStorm中的TypeScript导入/导出机制有问题。 比如说,我有一个名为apiUtils.ts的文件:

import apiUtils from "../bin/apiUtils";

const req = '';
const username = apiUtils.getUsername(req);
我还有另一个文件,它引用了apiUtils.ts:

import apiUtils from "../bin/apiUtils";

const req = '';
const username = apiUtils.getUsername(req);
getUsername方法未在运行中标识,我无法使用Ctrl+click导航到它。它被标记为未使用,我甚至可以编写以下代码并成功编译代码,而不会收到错误:

import apiUtils from "../bin/apiUtils";

const req = '';
const username = apiUtils.getUsername(req, thereIsNoSecontArgInThisMehod);
另一方面,如果我按如下方式导入方法:

import { getUsername } from "../bin/apiUtils";

const req = '';
const username = getUsername(req);
一切都会按预期进行:我得到导航、输入验证等等

我更喜欢使用从../bin/apiUtils导入apiUtils;而不是单独导入每个方法,因为这会造成方法的混乱,不清楚它们属于哪里,是否是本地的

是否有办法修复导入,并使其了解引用的方法?因为对于运行时,这两种方法都是一样的。

发生这种情况是因为导出默认模块。导出构造-我所知道的所有IDE都无法处理它们

如果要导入整个模块,请使用import*作为构造:

export function getUsername(req) {
    return req.headers.username;
}
import * as apiUtils from "../bin/apiUtils";

const req = '';
const username = apiUtils.getUsername(req);