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 }}
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
We are currently using React and Typescript in our application. We have a setup where we have defined a BaseComponent, containing a few common methods that we want a lot of our components to have.
Note: The identifier React is hard-coded, so you must make React available with an uppercase R.
So, in order for this to work, we had to import React as well by adding the following line in MyComponent:
import*asReactfrom"react";
But, tslint now throws an error on this because of the rule no-unused-variable as React is not being used anywhere within the tsx file. We would very much like to keep this rule in our linting configuration.
So, for the time being, we are using a gross hack like the following to use the unused React variable within MyComponent tsx file:
classDummyextendsReact.Component<{},{}>{}
So, my question to you is would you be able to support the kind of setup that we have? An ability to define exceptions to no-unused-variable rule perhaps? Or any other alternative solution that might resolve our issue by not resorting to that gross hack? I am assuming it won't be a one-off as I do see quite a few people who might want to be building React components in this way.
The text was updated successfully, but these errors were encountered:
It's cleaner and how we support disabling tslint for special cases. We could have an option to the no-unused-variable rule that allows you to define exceptions, but I feel like that might be unneeded complexity. Let me know how the above solution works for you and what you think of it.
Hi,
We are currently using React and Typescript in our application. We have a setup where we have defined a BaseComponent, containing a few common methods that we want a lot of our components to have.
Our BaseComponent looks like the following:
The rest of our components look like the following:
Now, this code will not compile as
React
needs to be in scope. React wiki says the following about the same at https://github.com/Microsoft/TypeScript/wiki/JSX#basic-usage:So, in order for this to work, we had to import React as well by adding the following line in MyComponent:
But, tslint now throws an error on this because of the rule
no-unused-variable
as React is not being used anywhere within the tsx file. We would very much like to keep this rule in our linting configuration.So, for the time being, we are using a gross hack like the following to use the unused React variable within MyComponent tsx file:
So, my question to you is would you be able to support the kind of setup that we have? An ability to define exceptions to
no-unused-variable
rule perhaps? Or any other alternative solution that might resolve our issue by not resorting to that gross hack? I am assuming it won't be a one-off as I do see quite a few people who might want to be building React components in this way.The text was updated successfully, but these errors were encountered: