在JavaScript中,向任何类型的prototype
添加函数和成员非常简单。我尝试在TypeScript中实现相同的功能,如下所示:
interface Date
{
Minimum: Date;
}
Date.prototype.Minimum = function () { return (new Date()); }
这会产生以下错误:
Type '() => Date' is not assignable to type 'Date'.
Property 'toDateString' is missing in type '() => Date'.
考虑到TS是强类型语言,我们如何实现这一点?
由于我正在用TS编写自定义实用程序库,所以我不想求助于JS。