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 have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
const foo: unknown = null;
const bar: object = foo!;
const baz: {} = foo!;
ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/no-unnecessary-type-assertion": "error"
}
}
tsconfig
Expected Result
I expected no error, because the non-null assertion is actually necessary. Typescript will allow you to assign a non-null asserted unknown
to object
or {}
, but won't if it isn't non-null asserted. Because an unknown
value can be null | undefined
, whereas object
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