#Inaccurate return type inference of generic context-bound function
14 messages · Page 1 of 1 (latest)
Preview:ts const myObject = { key1: "value1", key2: "value2", } class MyProxyHandler<T extends object> implements ProxyHandler<T> { constructor(protected log: (input: any) => void) {} public get( target: T, key: string | symbol, receiver: T ) { this.lo ...
apparently just binding a function with a declared this loses its generic
Preview:ts declare function f<T>(this: {}): T const x = f.bind({}) // ^?
if the this: {} is omitted, then the generic is preserved
found this open issue about retaining generics in general though #54707
😦
Thanks though!
Can anyone come up with a workaround?
const proxy1 = createProxy_bound(myObject) as typeof myObject
``` seems to work...
the issue i linked has a comment at the end that links to a SO post, which doesn't give any, so i'm not hopeful tbh
ah well yeah casting would probably resolve the immediate issue