Vscode-react-native: Type Aliases can only be used in a .ts file

Created on 17 Feb 2018  路  11Comments  路  Source: microsoft/vscode-react-native

Actual Behavior

  1. Eslint return a false positive error for Type Aliases can only be used in a .ts file
  2. This is due to the code in the auto generated app.js file from
type Props = {};
export default class App extends Component<Props> {

Expected Behavior

  1. No errors should be reported as the app.js file is generated from CLI tools
  2. 2.

Software versions

  • React-Native VS Code extension version:
  • VSCode version: 1.20.1

  • OS platform and version:
    Mac OS High Sierra

  • NodeJS version: 7.5
  • React Native version:
    react-native-cli: 2.0.1
    react-native: 0.53.0
external triaged waiting-for-clarification

Most helpful comment

I don't understand, why completely disabling JavaScript validation in VS is considered a valid solution? This isn't fixing the problem, it just hides and makes VS less usable.

All 11 comments

Hi @leejones45, sorry for the delayed response and thanks for reaching us. Could you please take a look at https://github.com/Microsoft/vscode/issues/5214#issuecomment-304566827 and let me know if it helps?

I followed instructions in that thread and solved my issues. Thanks.

I don't understand, why completely disabling JavaScript validation in VS is considered a valid solution? This isn't fixing the problem, it just hides and makes VS less usable.

I'm here from google.. can't believe this issue still hasn't been fixed!

For those still hitting this.. just set this in your preferences:

    "javascript.validate.enable": false,

I'm about to teach a whole workshop full of people that you need to do this to use flow with VSCode.. which makes VSCode look very poorly suited for JS!

I also use VSCode and a fix that I found was to change from this:

type Props = {};
export default class App extends Component<Props> {

to just this:

export default class App extends React.Component {

i.e. get rid of the type Props, and then change the App class' superclass from Component to React.Component.

Everything now works as expected. A bit odd that the default does not work in VSCode, I'm yet to find anything in the market place that adds support as well, but definitely seems to be a VSCode issue rather than a React-Native problem.

Hope this helps!

@ericvicenti What do you recommend for JS instead of vscode?

VSCode is still my favorite editor right now for JS, but I am confused by this configuration. Editors like Atom and Sublime Text do not have problems like this. Its still not clear why I have to disable "JS validation" in order to use a type system like flow..

Just install the new version of ESLint extension and be happy.

@FaustoCouto it seemed to work for a few seconds, and then the error returns

I really don't understand why this bug still cannot be fixed ? :\

Hi @buiqtuan. As it was explained before, extension itself have no control over managing this and all we can advice here is to use workarounds or ignore this error.
I have referenced this to the following issue in vscode repo: https://github.com/Microsoft/vscode/issues/49894 so I believe the better place for tracking status/leave feedback now is there.

Was this page helpful?
0 / 5 - 0 ratings