Skip to content

Conversation

@jbaldassari
Copy link
Contributor

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • [x ] other

Current behaviour

Currently TransportError is not exported, so if you want to check if an error is a TransportError in TypeScript with eslint you need to do something like this:

// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((error as any).type === 'TransportError') {
  ...
}

It's kind of a minor inconvenience, but many eslint configs prohibit the use of any, so it results in some extra boilerplate every time you need to do this check.

New behaviour

By exporting TransportError we will be able to import the type and perform the check like this:

if ((error as TransportError).type === 'TransportError') {
  ...
}

It should also make it possible to use instanceof instead: error instanceof TransportError.

Other information (e.g. related issues)

If this suggestion is accepted I'll make a follow-up PR to https://github.com/socketio/socket.io-client to export the type from there as well.

@darrachequesne darrachequesne merged commit c1795ef into socketio:main Nov 6, 2023
@darrachequesne
Copy link
Member

@jbaldassari thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants