Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.5.2&fileType=.tsx&code=GYVwdgxgLglg9mABAWwJ4DFwQBQEMBOA5gFyJggA2FiAPouACYCmwMYTDAlKYy2x4gDeAKESJ8TKCHxIChRAH4F9MM1bsGwgL5A&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0yHJgBNK%2BSpPRgA2uGyRE0aB2iQANKuyYDaofHgcA7gGFJyfEJYAZDh2I3ps%2BU1QZ8cRMYQAL7GALqqIUFAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
function myFunc(arg: null | undefined): undefined {
return arg ?? undefined
}
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-unnecessary-condition": [
"error",
{
"allowConstantLoopConditions": true
}
]
},
};
tsconfig
Expected Result
arg ?? undefined limits the union type null | undefined to just undefined so it's not unnecessary.
Actual Result
arg ?? undefined errors out like if it didn't restrict the union type a subset of its values.
Additional Info
No response
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.5.2&fileType=.tsx&code=GYVwdgxgLglg9mABAWwJ4DFwQBQEMBOA5gFyJggA2FiAPouACYCmwMYTDAlKYy2x4gDeAKESJ8TKCHxIChRAH4F9MM1bsGwgL5A&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0yHJgBNK%2BSpPRgA2uGyRE0aB2iQANKuyYDaofHgcA7gGFJyfEJYAZDh2I3ps%2BU1QZ8cRMYQAL7GALqqIUFAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
{ "compilerOptions": { "strictNullChecks": true } }Expected Result
arg ?? undefinedlimits the union typenull | undefinedto justundefinedso it's not unnecessary.Actual Result
arg ?? undefinederrors out like if it didn't restrict the union type a subset of its values.Additional Info
No response