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

Incorrect typings for ReadableStream #7217

Closed
ondras opened this issue Aug 27, 2020 · 12 comments
Closed

Incorrect typings for ReadableStream #7217

ondras opened this issue Aug 27, 2020 · 12 comments
Milestone

Comments

@ondras
Copy link
Contributor

ondras commented Aug 27, 2020

Hi,

my code uses the following tsconfig lib declaration:

"lib": ["dom", "dom.iterable", "deno.ns"],

after updating to Deno 1.3.1, the following TS error emerges:

error: TS2339 [ERROR]: Property 'getIterator' does not exist on type 'ReadableStream<R>'.
  return res.readable.getIterator();
                      ~~~~~~~~~~~
    at https://deno.land/[email protected]/async/pool.ts:45:23

...which is preventing me from running the code.

Thanks,
O.

@lucacasonato
Copy link
Member

I don't think this is a Deno issue. It seems the 'dom' type library (from typescript) doesn't include types for getIterator. So this looks like a upstream typescript issue.

@kitsonk
Copy link
Contributor

kitsonk commented Aug 28, 2020

Actually, we have a challenge. The specification was updated in June and getIterator() was renamed to values(). It was never implemented in Chrome as getIterator(). I guess this is the problem with implementing perpetually draft specifications. 🤷

@kitsonk
Copy link
Contributor

kitsonk commented Aug 28, 2020

Actually looking at that now, there is a whole load of changes there... 😭 it needs to be gone through with a fine toothed comb and realigned.

@ondras
Copy link
Contributor Author

ondras commented Aug 28, 2020

Is there at least a way to temporarily monkey-patch this (such as interface ReadableStream { getIterator ... }) so the code using the dom lib can be executed?

@kitsonk
Copy link
Contributor

kitsonk commented Aug 28, 2020

Interfaces are open ended. Something like this should work in your main module, assuming it is TypeScript:

declare global {
  interface ReadableStream<R = any> {
    getIterator(options?: { preventCancel?: boolean }): AsyncIterableIterator<R>;
  }
}

@ondras
Copy link
Contributor Author

ondras commented Aug 28, 2020

Interfaces are open ended. Something like this should work in your main module, assuming it is TypeScript:

Great, thanks @kitsonk!

(my naïve attempts were missing the declare global statement, thus failing to fix stuff)

@lucacasonato
Copy link
Member

Actually, we have a challenge. The specification was updated in June and getIterator() was renamed to values(). It was never implemented in Chrome as getIterator(). I guess this is the problem with implementing perpetually draft specifications. 🤷

Oh no! I was worried this was the case. This is going to definitely be a breaking change to fix, and it is going to break std types again 😭.

@kitsonk
Copy link
Contributor

kitsonk commented Aug 28, 2020

I suspect we can have values() and getIterator() for now and move all std over to values().

@timonson
Copy link
Contributor

This error still comes up. Is there a workaround?

@ondras
Copy link
Contributor Author

ondras commented Nov 17, 2020

This error still comes up. Is there a workaround?

The code mentioned in #7217 (comment) is a suitable workaround for my use case.

@timonson
Copy link
Contributor

It works indeed, thank you @ondras ! I misread kitsonk's comment the first time.

@lucacasonato lucacasonato added this to the 1.7.0 milestone Jan 4, 2021
@lucacasonato
Copy link
Member

This was resolved in #9103.

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

No branches or pull requests

4 participants