这是我的代码:
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中:
答案 0 :(得分:0)
似乎唯一确定的方法是创建一个名称不同的类型,但可以将其用于任何函数。
index.d.ts
type TdoThing = (is: boolean) => boolean;
example.d.ts
const doThing: TdoThing = x => `${x}`;
const doOtherThing: TdoThing = x => `${x}`;