You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSX and Salsa: Intellisense for ReactComponents does not work #7000
varCommentBox=React.createClass({render: function(){return(<divclassName="commentBox">
Hello, world! I am a CommentBox.
</div>);}});ReactDOM.render(<CommentBox/>,document.getElementById('content'));
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.
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.
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.
Is this rather an issue with the react.d.ts definition or some limitation of typings with the ES6 class syntax itself?
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.
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.
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.
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.
Hopefully these screenshots provide some insight into what I'm speaking of.
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.
Activity
egamma commentedon Feb 10, 2016
Did you install the corresponding .d.ts files?
egamma commentedon Feb 10, 2016
Does it work in this simple hello world example:
egamma commentedon Feb 10, 2016
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).

It does not offer the React-Component as the best option in your minimal example:

egamma commentedon Feb 10, 2016
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.
billti commentedon Feb 10, 2016
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.
nwehrle commentedon Feb 10, 2016
prashaantt commentedon Feb 18, 2016
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 theclass Test extends React.Componentway.Is this rather an issue with the
react.d.tsdefinition or some limitation of typings with the ES6 class syntax itself?mhegazy commentedon Feb 19, 2016
There are two issues going on here:
React. the problem is that the react module does not rely have a default export, the importing code uses the default importimport React from "react"instead of the namespace importimport * 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.
mhegazy commentedon Feb 19, 2016
This issue is tracking item 2 above, i.e. showing appropriate error message.
prashaantt commentedon Feb 20, 2016
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.For this to work, though, like I posted over on microsoft/vscode#2898 (comment) I have had to change the
modulein myjsconfig.jsontosystem. I discovered that accidentally, because if I now switch back tocommonjsthis only works for the commonjsrequires and no longer for the ES6 imports, like you say in point 2 above.billti commentedon Feb 22, 2016
This sounds like the same issue as #7076 . I'm looking into that.
2 remaining items
billti commentedon Feb 29, 2016
I have a fix out for the ES6-style imports, and confirmed it works in this scenario. See #7249 (comment)
patsissons commentedon May 5, 2016
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.
Hopefully these screenshots provide some insight into what I'm speaking of.
mhegazy commentedon May 7, 2016
Pat Sissons (@patsissons) what version of VSCode / TypeScript are you using?
patsissons commentedon May 7, 2016
mhegazy commentedon May 9, 2016
this issue is fixed in #7326. so should be available in the nightly builds (see https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Nightly%20Builds.md#visual-studio-code) or in the next release.
billti commentedon Jun 20, 2016
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
defaultproperty, and c) You do not haveallowSyntheticDefaultImportsset - then if you try to use a default import from the module perhaps a message likeThe 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.
mhegazy commentedon Sep 29, 2016
Bill Ticehurst (@billti) would this be handled by #10895?