Skip to content

Update target to ES6/ES2015 or ES2017 #243

@mrafnadeem-apimatic

Description

@mrafnadeem-apimatic

What

Currently, tsconfig.base.json targets ES5. It should target ES6/ES2015 at the very least. ES2017 would also work.

Why

Lack of Type Safety and Unexpected Behaviour

unknownInCatchVariables is a setting used to ensure type-safe handling of variables in the catch block since you can throw any object in JavaScript, not just Error.

When useUnknownInCatchVariables is disabled, the thrown error in the catch block is type any. If you use unknown in catch variables, you might be tempted to use instanceof in order to narrow it to an Error type. But this check returns false if you threw a class that inherits from Error. Why?

This is because we currently target ES5 in the tsconfig.json file.

Keeping it this way is dangerous for the codebase because it is easy to unintentionally introduce a bug in an effort to keep the code type-safe, since TypeScript won't warn us about this. We should upgrade.

References:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#custom_error_types
https://github.com/microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work

Inconsistency with SDKs

APIMatic's TS SDKs target ES2017. So as far as I can tell, there shouldn't be any users of the SDK who target pre-ES2017 environments.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions