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
I have a .tsx file with the following exported constant:
export const allTestCategories = -1
ESLint produces this error:
ERROR(ESLint) Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components. (react-refresh/only-export-components)
If I simply change the constant value from -1 to 1, the ESLint error goes away. Looking at only-export-components.ts line 105, I see that you are checking for Literal, TemplateLiteral, and BinaryExpression, but the problem is that -1 is a UnaryExpression. I think you need to add UnaryExpression to your logic.
I tried this as a workaround:
export const allTestCategories = -1 as number
This produced a TSAsExpression, which is also not handled by your logic. I'm not sure of all the implications, but it might make sense to allow this as well.
The text was updated successfully, but these errors were encountered:
I choose to not include TSAsExpression, it would require some extra checks on the expression being cast and I don't see any reason why you will need a type assertion for something that should be a primitive value.
My eslintrc.cjs contains:
I have a .tsx file with the following exported constant:
export const allTestCategories = -1
ESLint produces this error:
ERROR(ESLint) Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components. (react-refresh/only-export-components)
If I simply change the constant value from -1 to 1, the ESLint error goes away. Looking at only-export-components.ts line 105, I see that you are checking for Literal, TemplateLiteral, and BinaryExpression, but the problem is that -1 is a UnaryExpression. I think you need to add UnaryExpression to your logic.
I tried this as a workaround:
export const allTestCategories = -1 as number
This produced a TSAsExpression, which is also not handled by your logic. I'm not sure of all the implications, but it might make sense to allow this as well.
The text was updated successfully, but these errors were encountered: