Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Problem with super(props) #126

Open
amfahrj opened this issue Aug 30, 2019 · 5 comments
Open

Problem with super(props) #126

amfahrj opened this issue Aug 30, 2019 · 5 comments
Labels
bug Something isn't working as expected. help wanted The owner cannot resolve this on their own.
Milestone

Comments

@amfahrj
Copy link

amfahrj commented Aug 30, 2019

I've just started using reactn, when I switch to using

import React, {Component} from 'reactn'

in all my classes where I have

class FooBar extends Component<FooProps, FooState> {
constructor(props: FooProps) {
super(props);

I'm getting the following for error for the call to super(props)

Expected 0 arguments, but got 1.

I'm using TypeScript 3.6.2.

@quisido quisido self-assigned this Aug 31, 2019
@quisido quisido added the bug Something isn't working as expected. label Aug 31, 2019
@quisido
Copy link
Collaborator

quisido commented Aug 31, 2019

Thank you for the report. What happens if you use React.Component instead of destructuring Component? This may be related to #89, where the Component on the namespace is not the same as the class itself.

@amfahrj
Copy link
Author

amfahrj commented Sep 2, 2019

No change. To be clear, I changed the import to

import React from 'reactn'

The class definition to

class FooBar extends React.Component<FooProps, FooState> {

and I continue to receive the same error (Expected 0 arguments, but got 1) for the call to super(props)

@amfahrj
Copy link
Author

amfahrj commented Sep 4, 2019

Just to simplify, I created a new project. I followed the default instructions on the typescript docs here

https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter

I used the component version of Hello.tsx in those instructions.

In the Hello.tsx component I added

constructor(props: Props) {
super(props);
}

yarn build ran just fine.

Then, in the my-app directory I ran

npm install reactn

Finally, I modified the import statement in Hello.tsx to be

import * as React from 'reactn';

Failure at this point with

Expected 0 arguments, but got 1

on the call to super(props). This should make it easy to reproduce.

@quisido
Copy link
Collaborator

quisido commented Sep 5, 2019

This is reproducible/confirmed, but I'm not sure the best way to solve it right now. I believe this is a result of the issue I mentioned before where TypeScript cannot correctly infer the definition of Component.

For a current workaround, I would hope // @ts-ignore above super(props) would solve your issue, and you would still get all the valid type checking as far as this.global, etc.

As far as solving this officially, my current plan is to handle this in a 3.0 release, where I do not intend to extend the React namespace. It should clear up a lot of the edge cases with TypeScript today.

If you are not coding in the constructor (as in it only contains super), I would leave the constructor off, as it will default to super(props) without error.

Let me know if // @ts-ignore solves your problem. Sorry for the inconvenience!

@quisido quisido added the help wanted The owner cannot resolve this on their own. label Sep 5, 2019
@quisido quisido added this to the 3.0.0 milestone Sep 5, 2019
@quisido quisido removed their assignment Sep 5, 2019
@amfahrj
Copy link
Author

amfahrj commented Sep 5, 2019

Thanks. // @ts-ignore is how I was already handling it. That is working for the moment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working as expected. help wanted The owner cannot resolve this on their own.
Projects
None yet
Development

No branches or pull requests

2 participants