Skip to content

Conversation

@jstewmon
Copy link

When the target is ES5, typescript emits class inheritance code that is incompatible with instanceof checks in some cases.

A consequence of targeting ES5 is that library consumers cannot use instanceof type narrowing on errors thrown by the library:

try {
  const res = await gigya.accounts.getAccountInfo({UID});
} catch (err) {
  if (err instanceof GigyaError) {
    // unreachable when target is ES5
  } 
}

Bumping the target to ES2015 resolves this issue.

When the target is ES5, typescript emits class inheritance code that is [incompatible with instanceof checks](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work) in some cases.

A consequence of targeting ES5 is that library consumers cannot use `instanceof` type narrowing on errors thrown by the library:

```ts
try {
  const res = await gigya.accounts.getAccountInfo({UID});
} catch (err) {
  if (err instanceof GigyaError) {
    // unreachable when target is ES5
  } 
}
```

Bumping the target to ES2015 resolves this issue.
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.

1 participant