Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
constfoo:unknown=null;constbar:object=foo!;constbaz:{}=foo!;
ESLint Config
module.exports={"rules":{"@typescript-eslint/no-unnecessary-type-assertion":"error"}}
tsconfig
{"compilerOptions": {"strictNullChecks":true }}
Expected Result
I expected no error, because the non-null assertion is actually necessary. Typescript will allow you to assign a non-null assertedunknown
toobject
or{}
, but won't if it isn't non-null asserted. Because anunknown
value can benull | undefined
, whereasobject
and{}
disallow that.
Actual Result
There is an error on the non-null assertion. If autofixed, it turns into a Typescript error instead, because the assertion was not unnecessary.
Additional Info
No response