PhpStorm
 
Get PhpStorm
You are viewing the documentation for an earlier version of PhpStorm.

Code Inspection: Unsound type guard check

Last modified: 13 May 2022

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