Inspectopedia
 
2024.3

Unsound type guard check

Warning
Reliability
New
Last modified: 03 December 2024

Reports a typeof or instanceof unsound type guard check. The typeof x type guard can be unsound in one of the following two cases:

  • typeof x never corresponds to the specified value (for example, typeof x === 'number' when x is of the type 'string | boolean')

  • typeof x always corresponds to the specified value (for example, typeof x === 'string' when x is of the type 'string')

The x instanceof A type guard can be unsound in one of the following two cases:

  • The type of x is not related to A

  • The type of x is A or a subtype of A