如何解决如何使打字稿声明文件适用于函数类型
这是我的代码:
tsconfig.js
{
"compilerOptions": {
"baseUrl": "./","target": "es6","module": "commonjs","declaration": true,"strict": true,"esModuleInterop": true,"forceConsistentCasingInFileNames": true,"typeRoots": [
"node_modules/@types","./@types"
],"paths": {
"@types/*": ["@types/*"]
},},"exclude": ["node_modules"],"include": ["./*","@types"]
}
@ types / index.d.ts
interface Person {
is: boolean;
str: string;
}
type doThing = (is: boolean) => boolean;
example.ts
const jon: Person = {
is: 'hello world'
}
const doThing = x => `${x}`;
在example.js中:
- 找到并使用“人”的界面
- 找不到'doThing'的类型
解决方法
似乎唯一确定的方法是创建一个名称不同的类型,但可以将其用于任何函数。
index.d.ts
type TdoThing = (is: boolean) => boolean;
example.d.ts
const doThing: TdoThing = x => `${x}`;
const doOtherThing: TdoThing = x => `${x}`;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。