Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript support for callable ReactiveProxy<T>? #5

Open
micka190 opened this issue Nov 18, 2022 · 0 comments
Open

Typescript support for callable ReactiveProxy<T>? #5

micka190 opened this issue Nov 18, 2022 · 0 comments

Comments

@micka190
Copy link

I'm curious to know if ES6 class methods and other callback functions are officially supported by the r() function, or if they only work by coincidence.

I'm asking because the ReactiveProxy<T> type isn't callable, which means you get warnings/errors when using TS, but not when using JS. It also appears to work fine, so I'm not sure if it is intended behavior or not.

Here's an example of what I mean with an ES6 class:

class Foo {
  public mutateState(): void {
    // mutates internal class state here
  }
}

// ...

const data = r(new Foo())
data.mutateState(); // <-- This will get a Typescript warning/error

It yields the following warning/error:

  Type 'ReactiveProxy<() => void>' has no call signatures.

The same thing happens if I pass a function definition into the r() function instead of a new class (i.e. r({greet: () => alert('hi')}))

Like I said, though, having it mutate its own data works as expected (and even causes re-renders when placed in a template) if I tell Typescript to ignore the issue.

If it's intended to work, then maybe the ReactiveProxy<T> type needs a way to be callable?

If passing mutators into the r() method isn't intended, it would be useful to have it added to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant