Skip to content

JSX and Salsa: Intellisense for ReactComponents does not work #7000

Closed

Description

@egamma

From Norman Wehrle (@nwehrle) on February 10, 2016 11:52

Salsa is enabled:
bildschirmfoto 2016-02-09 um 22 13 44

But intellisense fails to offer proper React Elements:

bildschirmfoto 2016-02-10 um 10 57 12

bildschirmfoto 2016-02-10 um 10 59 01

System:
OSX 10.11.2
vscode 0.10.8
db71ac615ddf9f33b133ff2536f5d33a77d4774e

jsconfig.json:

{
  "compilerOptions": {
    "target": "ES6",
    "module": "system",
    "experimentalDecorators": true
  },

  "exclude": [
    "node_modules"
  ]
}

User settings:

{
  "javascript.validate.enable": false,
  "editor.tabSize": 2,
  "files.trimTrailingWhitespace": true,
  // Migrated from previous "File | Auto Save" setting:
  "files.autoSave": "onFocusChange"
}

Partial eslintrc:

 "rules": {
    "func-names": 0,
    "no-unused-expressions": 0,
    "id-length": 0,
    "no-multi-spaces": 0,
    "no-mixed-spaces-and-tabs": 2,

    "no-unused-vars": [1, {"vars": "all", "args": "none"}],
    "react/jsx-uses-react": 1,
    "react/prop-types": 0,
    "no-console": 0
  },
  "plugins": [
    "react"
  ]

Copied from original issue: microsoft/vscode#2886

Activity

  1. egamma commented on Feb 10, 2016

    @egamma
    MemberAuthor

    Did you install the corresponding .d.ts files?

    To get IntelliSense for React/JSX, install the typings for react-global by running tsd install react-global from the terminal.

  2. egamma commented on Feb 10, 2016

    @egamma
    MemberAuthor

    Does it work in this simple hello world example:

    var CommentBox = React.createClass({
      render: function() {
        return (
          <div className="commentBox">
            Hello, world! I am a CommentBox.
          </div>
        );
      }
    });
    
    ReactDOM.render(
      <CommentBox />,
      document.getElementById('content')
    );
  3. egamma commented on Feb 10, 2016

    @egamma
    MemberAuthor

    From Norman Wehrle (@nwehrle) on February 10, 2016 12:13

    You are right, I forgot to install the .d.ts file for the screenshot (but I tried before).
    bildschirmfoto 2016-02-10 um 13 04 57

    It does not offer the React-Component as the best option in your minimal example:
    bildschirmfoto 2016-02-10 um 13 08 08

  4. egamma commented on Feb 10, 2016

    @egamma
    MemberAuthor

    I see in your screenshot that you are using ES7 bind operator which is not yet supported by TypeScript which powers Salsa. As a consequence you get syntax errors and red squiggles which can make Intellisense fail.

    In the second screenshot you are correct that the React-Component could be proposed first, but the React-Component is proposed so Intellisense is working but the sorting isn't optimal.

    Moving over to TypeScript as an FYI.

  5. billti commented on Feb 10, 2016

    @billti
    Member

    I've discussed this internally before with Ryan Cavanaugh (@RyanCavanaugh) . The challenge is with things like stateless functional components, any function really could be a valid React element, not just those types which derive from React classes/components.

    I assume the identifier you require is in the list and starts filtering down when you type?

    Arguably we could do a better job of filtering out things like interface names from the list, but that is a general issue with the global identifier list, and orthogonal to React.

    Assigning to Ryan to see if he has any further input, else I believe this is by design.

  6. nwehrle commented on Feb 10, 2016

    @nwehrle

    I assume the identifier you require is in the list and starts filtering down when you type?
    Yes it does, but it does not look like your screenshot, https://code.visualstudio.com/images/January_jsx-salsa.png - it looks like any other available var.

  7. prashaantt commented on Feb 18, 2016

    @prashaantt

    I'm new to TypeScript so please excuse me if this is silly. I do get IntelliSense for React via typings if I try accessing typings statically or inside the React.createClass() syntax, but not inside a component if I have declared an ES6 class the class Test extends React.Component way.

    screenshot 2016-02-18 21 31 51

    screenshot 2016-02-18 21 38 16

    Is this rather an issue with the react.d.ts definition or some limitation of typings with the ES6 class syntax itself?

  8. mhegazy commented on Feb 19, 2016

    @mhegazy
    Contributor

    There are two issues going on here:

    1. the completion inside the class doe not show inherited properties at the moment, this is a feature that the TS language service does not support. but it is a fair request to add. added issue for it:Populate inheritied properties and methods in completion list inside a class #7158
    2. the completion on React. the problem is that the react module does not rely have a default export, the importing code uses the default import import React from "react" instead of the namespace import import * as React from "react". Transpilers like Babel fudge this difference by a runtime check, but it is really a lie, and the module does not have a default export, and would not work without a transpiler.
      Ideally you should see a helpful message about this, and that is what we should fix.
  9. mhegazy commented on Feb 19, 2016

    @mhegazy
    Contributor

    This issue is tracking item 2 above, i.e. showing appropriate error message.

  10. prashaantt commented on Feb 20, 2016

    @prashaantt

    Mohamed Hegazy (@mhegazy) As I mentioned in my last comment, auto-complete on React. does work well for me if I have the typings in place.

    screenshot 2016-02-20 15 11 47

    For this to work, though, like I posted over on microsoft/vscode#2898 (comment) I have had to change the module in my jsconfig.json to system. I discovered that accidentally, because if I now switch back to commonjs this only works for the commonjs requires and no longer for the ES6 imports, like you say in point 2 above.

  11. billti commented on Feb 22, 2016

    @billti
    Member

    this only works for the commonjs requires and no longer for the ES6 imports, like you say in point 2 above

    This sounds like the same issue as #7076 . I'm looking into that.

  12. 2 remaining items

  13. billti commented on Feb 29, 2016

    @billti
    Member

    I have a fix out for the ES6-style imports, and confirmed it works in this scenario. See #7249 (comment)

  14. patsissons commented on May 5, 2016

    @patsissons

    I'm running into a similar issue, but I'm not sure if it is the same as what has been discussed here. Most of the comments here appear to be with intellisense in a code block. My issue is that my react components are not showing up in the intellisense only for JSX blocks. Once I create the JSX element, the intellisense works for the attributes on the JSX element, just not for the initial creation of the element.

    code-block
    jsx-block-creation
    jsx-block-attributes

    Hopefully these screenshots provide some insight into what I'm speaking of.

  15. mhegazy commented on May 7, 2016

    @mhegazy
    Contributor

    Pat Sissons (@patsissons) what version of VSCode / TypeScript are you using?

  16. patsissons commented on May 7, 2016

    @patsissons

    VSCode version
    typescript version

  17. mhegazy commented on May 9, 2016

    @mhegazy
    Contributor
  18. billti commented on Jun 20, 2016

    @billti
    Member

    I believe all the issues discussed above are either fixed or explained, with the exception of Mohamed Hegazy (@mhegazy) 's comment that the error message should be improved when trying to use a default import that doesn't exist (and without allowSyntheticDefaultImports).

    Mohamed Hegazy (@mhegazy), did you have any thoughts on how this should behave? This is for JavaScript, so it may well be that you have no definitions for the imported module, and that is not an error. Seems that if: a) There is a definition we can use for the imported module, and b) That definition does not contain a default property, and c) You do not have allowSyntheticDefaultImports set - then if you try to use a default import from the module perhaps a message like The module referenced does not export a default property. Did you mean to import an identifier list or a namespace, or set "allowSyntheticDefaultImports" to true?.

    Even then, this is a little weird, as this is still a 'type system' error on a JavaScript file, and users may not be aware of the "synthetic default" and how different module systems interact with it.

  19. modified the milestones: , TypeScript 2.1 on Sep 29, 2016
  20. mhegazy commented on Sep 29, 2016

    @mhegazy
    Contributor

    Bill Ticehurst (@billti) would this be handled by #10895?

  21. added
    VS Code Tracked
    on Dec 16, 2016
  22. removed this from the milestone on Apr 26, 2018
  23. locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugVS Code Tracked

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions