-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Improving IntelliSense for React Components in JavaScript #15251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I may be missing something obvious, but why would using propTypes not be feasible? Why would
inside a class not be doable to infer type bindings for |
Someone on the TypeScript team may be able to speak to this better, but I don't think we can pick up types from a static property like that. A TypeScript server extension may be able to enrich TypeScript's knowledge of the component however |
I guess I'm speaking more on the VS Code side, than TypeScript. I'm not sure if VS Code does any sort of type inference on its own, or it's just limited to what TypeScript would do. I can see why TypeScript wouldn't bake in React support to their language; I had just assumed VS Code would be able to, assuming the file is javascriptreact or typescriptreact, be able to sniff out propTypes on a class component definition. But no complaints - we're really loving VS Code :) |
You could use /**
* @augments {Component<{x: string, y:number}}, State>}
*/
class MyComponent extends Component {
...
} Now the type of As for bake-in inferences for react, we have always shied away from baking-in any type inferences for frameworks. we believe a better approach is to add more power to the language to allow users to explicitly declare their intent, hence the |
@mhegazy thank you SO much. Worked like a charm! btw I definitely don't think TypeScript should bake in React stuff - that comment should have been made on the VS Code issue, not here. Apologies, and thanks again! |
Closing since I believe the original question has been answered |
I tried this workaround, but it doesn't seem to work with such a syntax:
I tried:
or
without success. |
From: microsoft/vscode#24926
Problem
For a simple react component defined in a JavaScript file:
I was unable to figure out how to get proper intellisense inside of
Component
. Specific problems:Component
provided inside ofMyComponent
when typingthis.
props
orstate
using jsdocs.microsoft/vscode#24926 suggested that we use the PropTypes object for IntelliSense. I'm not sure this is feasible, although someone could probably write a TSServer plugin to do this.
However, I also wasn't able to write a jsdoc that provides proper IntelliSense here. Is there any way to do this currently?
The text was updated successfully, but these errors were encountered: