Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade TypeScript 2 to something newer #167

Open
generalmimon opened this issue Feb 9, 2024 · 0 comments
Open

Upgrade TypeScript 2 to something newer #167

generalmimon opened this issue Feb 9, 2024 · 0 comments

Comments

@generalmimon
Copy link
Member

generalmimon commented Feb 9, 2024

See #166 (comment) (cc @GreyCat)

When adding the js-yaml dependency in #166, I couldn't use the TypeScript definitions available in the DefinitelyTyped repo directly, because they use unknown. The unknown type is a feature introduced in TypeScript 3.0 (see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type), but we're currently using TypeScript 2, see package.json:

"typescript": "^2.9.2"

So I had to copy the TS definitions to lib/ts-types/js-yaml.d.ts and patch it (i.e. replace unknown by any) to make it compatible with TypeScript 2:

// Adapted from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/65afafadd93759348909de1cdad5df5789c94326/types/js-yaml/index.d.ts
// 1. fixed compatibility with TypeScript 2 (which we're still
// using at the time of writing) by replacing `unknown` with `any`

I believe migrating from TypeScript 2 would allow us to drop our lib/ts-types directory altogether and use the packages in the @types namespace at npm instead. For example, for the js-yaml library, this would be just a matter of adding @types/js-yaml as a dependency (according to my tests, the TS compiler automatically resolves the installed @types/* packages, so no more steps are needed).

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

No branches or pull requests

1 participant