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

Working TypeScript example, can't get it to work #119

Closed
MarkusWendorf opened this issue Oct 17, 2018 · 13 comments
Closed

Working TypeScript example, can't get it to work #119

MarkusWendorf opened this issue Oct 17, 2018 · 13 comments

Comments

@MarkusWendorf
Copy link

Good evening,

I'm trying to get unistore to work with TypeScript and properly type my store. I would like to ask for some help on my example (Typescript on React).

Repo: Unistore TypeScript
I'm getting an error: TS2604: JSX element type 'App' does not have any construct or call signatures.
If I ignore the error with @ts-ignore everything works as expected.

What am I missing?

PS:
I would appreciate if you would include a working TypeScript example with every release.

@joseluisq
Copy link
Contributor

Here a TypeScript (TSX) working example using v3.1.0 https://github.com/joseluisq/preact-starter

@stephan281094
Copy link

I'm having the same issue, using React. It seems as if connect returns an instance of the component, instead of the constructor. Have a look at the following code snippet.

import * as React from "react";
import { render } from "react-dom";
import createStore from "unistore"
import { connect, Provider } from "unistore/react";

const store = createStore({ bar: "baz" });

const Foo = connect("bar")((props: any) => (
  <h1>{props.bar}</h1>
));

// Throws "JSX element type 'Foo' does not have any construct or call signatures. [2604]".
const App = () => (
  <Provider store={store}>
    <Foo />
  </Provider>
);

render(<App />, document.querySelector(".mount"));

@types/react: 16.7.7
React: 16.6.3
Typescript: 3.1.6
Unistore: 3.1.0

@stephan281094
Copy link

@joseluisq Excuse me for the direct mention. Do you also have a working example in React?

@joseluisq
Copy link
Contributor

joseluisq commented Nov 27, 2018

@stephan281094 No, I don't have one but did you tried this?

@stephan281094
Copy link

@joseluisq I actually meant an example where they use both React and TypeScript. The example of ReactStateMuseum isn't written in TypeScript.

To clarify, I did manage to get unistore working with React in plain javascript, but not with TypeScript due to the error @MarkusWendorf is describing in this issue.

@joseluisq
Copy link
Contributor

@joseluisq I actually meant an example where they use both React and TypeScript. The example of ReactStateMuseum isn't written in TypeScript.

To clarify, I did manage to get unistore working with React in plain javascript, but not with TypeScript due to the error @MarkusWendorf is describing in this issue.

Sorry by my incomprehension.

@joseluisq
Copy link
Contributor

joseluisq commented Nov 27, 2018

Here my exploration about the current error:

unistore/preact
screen shot 2018-11-27 at 15 44 26

Preact.ComponentConstructor as result

unistore/react
screen shot 2018-11-27 at 15 42 55

React.Component as result

unistore/react
screen shot 2018-11-27 at 15 46 43

Note: Just changing React.Component with React.ComponentClass solves the issue.

Thoughts?

@stephan281094
Copy link

Thanks for the quick response. Your change got rid of the error, great work! Not sure if this change is compatible with previous versions of React though. Might require some research.

@developit
Copy link
Owner

looks like React.ComponentClass has been available since React 15.

@developit
Copy link
Owner

I've opened a PR with the above change.

@stephan281094
Copy link

Awesome, thanks!

@developit
Copy link
Owner

Released as 3.2.0!

@joseluisq
Copy link
Contributor

👍

@developit Is #127 issue already fixed too?

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

4 participants