TS1228

error TS1228: A type predicate is only allowed in return type position for functions and methods.

Broken Code ❌

1
2
3
function hasErrorCode(error: any) error is {code: string} {
return typeof (error && error.code) === 'string'
}

Fixed Code ✔️

You have to separate the argument list from the return type definition by a ::

1
2
3
function hasErrorCode(error: any): error is {code: string} {
return typeof (error && error.code) === 'string'
}