ESLint rule for not passing type into useState?

Hey guys, is there a ESLint rule I can enable to give me a error when Im not passing a type into useState? I thought this would have been standard, so maybe this isn't the correct pattern, but I would have thought best practice would be to enforce type declaration on state? Example:
const [prevBtnEnabled, setPrevBtnEnabled] = useState<boolean>(false);
const [nextBtnEnabled, setNextBtnEnabled] = useState(false);
const [prevBtnEnabled, setPrevBtnEnabled] = useState<boolean>(false);
const [nextBtnEnabled, setNextBtnEnabled] = useState(false);
I would expect the bottom one to have an error, but it doesn't. Is the top the correct pattern, or should I be doing something different?
3 Replies
Tom
Tom2y ago
Theo has a whole opinion on this, but basically the type on the bottom one is implied from the variable. I kinda like explicit typing but Theo (and many others) argue that you should use implicit typing whenever possible
Cody
Cody2y ago
I am certainly team implicit types! However, I often like to pass through an OR NULL type so I can use nullish coalescing to check if state has been set (ex numbers when 0 is acceptable) Maybe I should just be passing the type only when needing it rather than declaring for all states
Tom
Tom2y ago
yeah thats what i do
Want results from more Discord servers?
Add your server