I am to trying add a method to Function.
The problem is that the return value dose not automaticlly inherit T.
interface Function {
Promise <T> (...args: any[]): Promise<T> ;
}
Function.prototype.Promise = async function <T> (this: Function , ...args: any[]): Promise <T> {
return new Promise <T> ((resolve, reject) => {
this(args).then((x: T) => resolve(x)).catch((e: any) => reject(e));
});
}
var test =(async()=> {
return "";
});
// this return Promise<unknown> it should return Promise<string>
test.Promise()
// this should work, but I want the above to work instead
// it should inherit the type automaticly
test.Promise<string>()