Reputation: 20364
I have turned on Resharper Ultimate on a .Net Core Web Application that is using TypeScript to code React Components.
So I have a simple component class;
export class Index extends React.Component<{},{}>{
Resharper is warning me that
Generic type '_$_$RsRpExt"FromFile;....\node_modules\@types\react\index.d.ts, module=JavaScriptReferencedFilesModule:Referenced external files".React.Component' requires 1 type argument(s), but got 2
My npm packages for react are;
Dependencies:
"react": "^15.6.1",
"react-dom": "^15.6.1",
Dev Dependencies
"@types/react": "^15.0.39",
"@types/react-dom": "^15.5.1",
Looking at the typed files, I can see that the React Component takes in 2 arguments as it should:
interface Component<P = {}, S = {}> extends ComponentLifecycle<P, S> { }
class Component<P, S> {
constructor(props?: P, context?: any);
I am using webpack to compile the TS/TSX files and it is all working and the project works, however it is going to be annoying if Resharper is not playing well with the TypeScript code.
Anyone know a way to resolve this?
Upvotes: 12
Views: 3070
Reputation: 3607
In VisualStudio 2019 / Resharper 2019.1 you can now enable JSX syntax in JS files. You can do this by following these steps:
Extensions - Resharper - Options - JavaScript - Inspections - Enable JSX syntax in JS files: Always
I also changed my JavaScript language Level to ECMAScript 2016 but I think that is not necessary.
Upvotes: 17
Reputation: 413
The current Resharper version (2017.1) only supports TypeScript 2.2. The React type definitions use generic parameter defaults, which is a TypeScript 2.3 feature and is not recognized properly by Resharper 2017.1. Resharper 2017.2 (currently in EAP) will support TypeScript 2.4.
In the meantime, I just turned off Resharper's JavaScript/TypeScript support (via Resharper => Options => Products and Features) and use the VS TypeScript language support. This works fine.
Upvotes: 9