observable-slim icon indicating copy to clipboard operation
observable-slim copied to clipboard

In Typescript, create function returns wrong type

Open thomaswp opened this issue 2 years ago • 0 comments

In your type definitions, the ObservableSlim.create() function returns a type ProxyConstructor. I think this is incorrect. ProxyConstructor is just a type defined explicitly for the object Proxy, and all it can do is be constructed, i.e. new Proxy(...).

If I run:

let x = {} as MyState
let state = ObservableSlim.create(x, true, changes => {
    console.log('State changed', changes);
});
x.y = 3;

I would expect state to be of type MyState, or possibly object, but definitely not ProxyConsructor. I get an error on the last line, even if the type MyState has a property x. If you construct a Proxy, it will be of the same type as the first argument, so I think create should world the same way.

thomaswp avatar Mar 10 '24 01:03 thomaswp