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

TypeScript typings fail to compile without downlevelIteration=true #334

Closed
octogonz opened this issue Nov 13, 2021 · 3 comments
Closed

TypeScript typings fail to compile without downlevelIteration=true #334

octogonz opened this issue Nov 13, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@octogonz
Copy link

octogonz commented Nov 13, 2021

Describe the bug

The TypeScript typings for the yaml package fail to compile unless the downlevelIteration=true compiler option is enabled in the consuming project's tsconfig.json file.

To Reproduce

Attempt to compile some TypeScript code that does import * as yaml from 'yaml'; with downlevelIteration=false.

The error messages look like:

[typescript] Error: yaml/dist/nodes/Collection.d.ts:56:14 - (TS2569) Type 'Iterable<unknown>' is 
not an array type or a string type. Use compiler option '--downlevelIteration' to 
allow iterating of iterators.

The problem lines look like:

yaml/dist/nodes/Collection.d.ts

    /**
     * Removes a value from the collection.
     * @returns `true` if the item was found and removed.
     */
    deleteIn([key, ...rest]: Iterable<unknown>): boolean;
             ^^^^^^^^^^^^^^

Expected behaviour

We have this setting disabled in some of our projects that target ES5. The reason is that performance is very important, and transpilation of downlevelIteration was considered too expensive for those projects. Iterators are a nice language feature, but to ensure broadest compatibility with all potential consumers, a library package such as yaml should not rely on this feature in its API.

Note that I'm not insisting for yaml/**/*.js to adopt a particular transpilation strategy. This is merely a request that the .d.ts files should be declared in a way that will compile without errors.

Versions (please complete the following information):

  • Environment: Node v14.15.4
  • yaml: ~2.0.0-8
  • TypeScript compiler: 4.2.4
@octogonz octogonz added the bug Something isn't working label Nov 13, 2021
@eemeli
Copy link
Owner

eemeli commented Nov 13, 2021

That's an entirely reasonable request, esp. as the current destructuring was leaking implementation details to the types.

@octogonz Would you have a way of verifying that the current master branch fixes your issues?

@eemeli
Copy link
Owner

eemeli commented Nov 13, 2021

Managed to first recreate the issue with yaml@2.0.0-8 and then verify that this issue is fixed with the change in ed5d1db.

This allows for compilation with the following TS compiler options:

{ target: 'es5', lib: ['es2015'], downlevelIteration: false }

@octogonz
Copy link
Author

@eemeli I have confirmed that this issue is resolved in yaml@2.0.0-9. It works awesome! Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants