Skip to content

Use TS typeguard for utils/is helpers #2240

@CPatchane

Description

@CPatchane

Hey 👋

In the utils/is file we have some helpers to check identities, but all functions just return boolean. What about using TS typeguard for that?

For example with the isError function:

export function isError(wat: any): boolean {...}
// become
export function isError(wat: any): wat is Error {...}

Then it will allow to do:

// myException type is: string | Error
if (!isError(myException)) {
  return event;
}
// previously we got the error: Property "name" doesn't exist on type string
const name = myException.name // no more need to cast to continue using it as an Error

What do you think?
This might be a big change internally (or not) since those are utils helpers and used everywhere but I could help if you need some PRs :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions