【发布时间】:2021-02-06 06:33:27
【问题描述】:
我正在使用 typescript,但无法使用另一个文件中声明的接口。
我的global.d.ts 看起来像这样。
declare interface IPropSendEmail {
from: string,
to: string,
subject: string,
html: string,
}
下面是tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./build",
"esModuleInterop": true,
"declaration": true,
"strict": true,
"typeRoots": [
"types"
],
}
}
目录结构如下所示
| -- src
|-- types
|-- global.d.ts
|-- util
|-- common.ts
|-- ...
在common.ts 文件中使用它
export async function sendEmail({ from, to, subject, html }: IPropSendEmail) {
// function code here
...
}
【问题讨论】:
-
这对我们来说信息不足,请提供更多上下文(例如,还有什么文件,您打算如何使用它等)。
标签: typescript declaration typescript-typings