Giter Club home page Giter Club logo

Comments (5)

mijay avatar mijay commented on July 16, 2024

I have a similar issue. When I write the following (valid) code:

const ObservedMyComponent = observer(MyComponent);
createElement(ObservedMyComponent, { key: "12" });

I get the following error on the second line:

error TS2345: Argument of type 'ComponentClass<any> | void' is not assignable to parameter of type 'ComponentClass<any> | StatelessComponent<any>'.
  Type 'void' is not assignable to type 'ComponentClass<any> | StatelessComponent<any>'.
    Type 'void' is not assignable to type 'StatelessComponent<any>'.

After some juggling around, I've figured out that the problem is in the following line in your package typings:

export function observer<TFunction extends React.ComponentClass<any>>(target: TFunction): TFunction | void; // decorator signature

If you remove the void case, everything works as expected.

Typescript 1.7.5, React 0.14

from mobx-react.

mweststrate avatar mweststrate commented on July 16, 2024

I tried to reproduce this issue (see the above commit), however the above error didn't occur.

Does the test https://github.com/mweststrate/mobservable-react/blob/master/test/ts/compile-ts.tsx properly reproduce the issue? Feel free to amend.

Test can simply be run by cloning the repo and running tsc -p test/ts

from mobx-react.

mweststrate avatar mweststrate commented on July 16, 2024

Maybe a different version of react.d.ts?

from mobx-react.

mijay avatar mijay commented on July 16, 2024

Didn't have a time to double check it yet, but your tests are missing the case where I got an error:

class T7 extends Component<{ pizza: number}, {}> {
    render() {
        return <div>{this.props.pizza}</div>;
    }
}
React.createElement(observer(T7), { pizza: "4 seasons" });

from mobx-react.

mweststrate avatar mweststrate commented on July 16, 2024

Tnx. That was the culprit indeed! Fixed and released as 2.1.5

from mobx-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.