Rule clash when using no-useless-undefined
, no-null
, TypeScript and React.createContext
#1684
Labels
no-useless-undefined
, no-null
, TypeScript and React.createContext
#1684
I added
plugin:unicorn/recommended
to a few side projects and my code got noticeably more coherent. Great plugin folks!I have noticed one interesting clash between linting rules and wonder if it can be addressed by the plugin. Here’s my original TypeScript code (before Unicorn):
Once I added recommended Unicorn rules, I got saw near error near
export const MyContext
):Use `undefined` instead of `null` (unicorn/no-null)
. Me: OK,Unicron:
Do not use useless `undefined` (unicorn/no-useless-undefined)
. Me: OK,TypeScript:
Expected 1 arguments, but got 0.
. Me: React typings must be incomplete and I should submit a PR that allows omittingundefined
. React typings:Link: DefinitelyTyped/DefinitelyTyped#24509 (comment). Me: Hmm, this looks like a dead end 😅
Assuming that we can’t easily update React typings, looks like we should either:
null
increateContext
/React.createContext
or
undefined
as useless if it’s an argument ofcreateContext
/React.createContext
.In the meantime, my workaround is:
+ // eslint-disable-next-line unicorn/no-useless-undefined const MyContext = React.createContext<MyContextValue | undefined>(undefined);
or:
For the record, I am using
eslint-plugin-unicorn@40.0.0
and@types/react@17.0.38
. WDYT folks?The text was updated successfully, but these errors were encountered: