wix-incubator / vscode-glean

The extension provides refactoring tools for your React codebase
MIT License
1.46k stars 56 forks source link

Error for simple component conversion #51

Closed OliverJAsh closed 5 years ago

OliverJAsh commented 5 years ago

Property value expected type of string but got null

TS 3.1.6 VS Code 1.30.2 Extension version 4.2.3

import React, { Component } from 'react';

class App extends Component<{}> {
  render() {
    return (
      <div />
    );
  }
}

image

borislit commented 5 years ago

Hey @OliverJAsh ! Thanks for the report. Ill check it out right away. Keep in mind, currently, there is an issue in publishing a new version to the market.

borislit commented 5 years ago

@OliverJAsh IUnfortunatly i was un able to reproduce (see gif below). Perhaps some details are missing? 51

ecbrodie commented 5 years ago

@borislit I also got this error when doing a simple conversion, although for me it was the other way around. It was in a .tsx file, so not sure if Typescript is causing an issue here. Here's some code to try to reproduce the issue, via converting from a stateless to a stateful component (with all code from export default function Test to the end of the file highlighted):

import React from "react"

type Props = {
  foo: string
}

export default function Test({ foo = "bar" }: Props) {
  return <div>Foo = {foo}</div>
}

My workspace:

borislit commented 5 years ago

Hey @ecbrodie ! Ill give it another go later today and keep you posted! Thanks for reporting!

borislit commented 5 years ago

@ecbrodie i found the issue. It has to do with incorrect handling of default prop values. Im working on a fix. meanwhile, if u remove the = "bar" it'll work

borislit commented 5 years ago

@ecbrodie https://github.com/wix/vscode-glean/commit/3cf1c6589359902988566ac2fa8cc74dc6fd3881 should fix the issue. It also adds support for defaultProps. Tell me how it goes. Thanks

ecbrodie commented 5 years ago

@borislit I just checked the latest version of Glean and it now works without error when there are default prop values. Thank you for the quick turnaround.

Also, I checked the example from the OP (@OliverJAsh) and that conversion also works without error. Thus, with default props, I have confirmed that stateful-to-stateless and stateless-to-stateful conversions are working just fine. I think this issue can be closed.

borislit commented 5 years ago

Thanks @ecbrodie ! Glad to help!

OliverJAsh commented 4 years ago

I'm still running into this error, using 5.0.1.

Screenshot 2020-06-08 at 14 54 20

I also get the same error when I try "wrap with useMemo":

Screenshot 2020-06-08 at 14 55 21

And "wrap with useEffect" produces a lot of weird code. Input:

import * as React from 'react';

const App = () => {
    Math.random();
    return <div />;
};

Output:

import * as React from 'react';

const App = () => {
    var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

React.useEffect(() => {
  () => {
    Math.random();
  };
});
    return <div />;
};
borislit commented 4 years ago

Hey @OliverJAsh ! Thanks for the report. Will have a look ASAP

techsin commented 3 years ago

Also it shows up in non react code everywhere.