Is it possible to enforce the copy
function to extend the original
function, even when the parameters of the fnGenerator
are in reverse order?
Can this be achieved?
function fnGenerator<Original extends Copy, Copy extends Function>(copy:Copy,original:Original){}
function original(props:{a?:number,z:number}):number { return 2}
function copy(props:{a:number}):number { return 1}
// Currently, `original` is facing compilation errors instead of `copy`
fnGenerator(copy,original)
Real usecase:
function fallback<OriginalFn extends Function>(props: {fallback:OriginalFn}) {
return function (target: any,
propertyKey: string,
descriptor: Omit<PropertyDescriptor,'value'> & { value?: OriginalFn}
) {
return descriptor
};
}
class MyClass1 {
// I expect a compilation error but it works
@fallback({fallback: (props: {x:number,z:number})=>{ return 0} })
static method1(pros:{x:number, z?: number}):number {
return 1
}
}