【发布时间】:2023-02-05 13:49:08
【问题描述】:
我要创建类型的函数如下(scratch-parser 的一部分):
module.exports = function (input, isSprite, callback) {
// Unpack the input and further transform the json portion by parsing and
// validating it.
unpack(input, isSprite)
.then(function (unpackedProject) {
return parse(unpackedProject[0])
.then(validate.bind(null, isSprite))
.then(function (validatedProject) {
return [validatedProject, unpackedProject[1]];
});
})
.then(callback.bind(null, null), callback);
};
我为这个函数创建了一个类型,但是这个函数是匿名的,所以我不能断言这个类型。
declare function scratchParser(
input: Buffer | string,
isSprite: boolean,
callback: (
err: Error,
project: ScratchParser.Project | ScratchParser.Sprite,
) => void,
): void;
如何通过module.exports断言匿名函数的类型?
【问题讨论】:
标签: typescript