小编E. *_*erg的帖子

如何从节点模块导出Typescript接口?

弄清楚了!

最初,我试图像这样导入我的模块:

const qml = require('quill-marking-logic')
const { checkSentenceCombining, checkSentenceFragment, checkDiagnosticQuestion, checkFillInTheBlankQuestion, ConceptResult } = qml
Run Code Online (Sandbox Code Playgroud)

因为TS2307: Cannot find module 'quill-marking-logic'尝试使用时出现错误

import { checkSentenceCombining, checkSentenceFragment, checkDiagnosticQuestion, checkFillInTheBlankQuestion, ConceptResult } from 'quill-marking-logic'

这是因为我是用"module": "es6"我的进口程序的tsconfig,默认设置moduleResolution选项Classic。通过将其显式设置为node,我可以使用import语法并获取接口!

原始帖子

我使用Typescript构建了一个节点模块,该模块在另一个应用程序中用作依赖项。我在模块中尝试从其入口点导出几个接口,以便可以在其他应用程序中使用它们,但是在编译后将其删除。我知道这是Typescript设计的一部分,因为这些接口用于运行时分析,但是我想知道是否有一种解决方法,因此我不必在我的其他应用中再次定义它们相同的代码在两个地方。我正在使用汇总作为捆绑程序。

这是我的入口点的.d.ts版本如下所示:

export { checkSentenceCombining } from './libs/graders/sentence_combining';
export { checkDiagnosticQuestion } from './libs/graders/diagnostic_question';
export { checkSentenceFragment } from './libs/graders/sentence_fragment';
export { checkFillInTheBlankQuestion } from './libs/graders/fill_in_the_blank';
export { Response, PartialResponse, ConceptResult, FocusPoint, IncorrectSequence, FeedbackObject, …
Run Code Online (Sandbox Code Playgroud)

node.js node-modules typescript rollupjs

5
推荐指数
2
解决办法
4516
查看次数

标签 统计

node-modules ×1

node.js ×1

rollupjs ×1

typescript ×1