TS18046
error TS18046: ‘
error
‘ is of type ‘unknown
‘.
Broken Code ❌
1 |
|
Fixed Code ✔️
If you set the useUnknownInCatchVariables
option to true
in your tsconfig.json
file, you may encounter the TS18046 error.
Enabling the useUnknownInCatchVariables feature causes the error within a catch clause to be treated as the unknown
type instead of any
. As a result, you will need to incorporate a type guard or an assertion function to access properties on an object of type unknown
:
1 |
|