denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.67k stars 5.34k forks source link

Add a lib to cover async iterables in the DOM #9218

Closed ebebbington closed 3 years ago

ebebbington commented 3 years ago

Before 1.7.0, i had an encountered another error, with the hopes 1.7 would fix it... and it did, but just another error has popped up now

// a.ts
import * as whatever from "https://deno.land/std@0.84.0/async/pool.ts"
// tsconfig.json
{
  "compilerOptions": {
    "lib": [
      "deno.ns",
      "dom",
      "dom.iterable",
      "ES2018"
    ]
  }
}
$ deno run -A --config tsconfig.json a.ts

error: TS7053 [ERROR]: Element implicitly has an 'any' type because expression of type 'symbol' can't be used to index type 'ReadableStream<R>'.
  return res.readable[Symbol.asyncIterator]();
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    at https://deno.land/std@0.84.0/async/pool.ts:45:10
lucacasonato commented 3 years ago

This is an upstream Typescript issue. They should add typings for ReadableStream being an async iterator to lib.dom.

ebebbington commented 3 years ago

@lucacasonato Should i log an issue with them instead then?

kitsonk commented 3 years ago

Not in lib.dom in lib.dom.iterable @lucacasonato but for some reason they don't have any async iterables in there.

There is already an issue: https://github.com/microsoft/TypeScript/issues/29867

Considering that it has been open for a couple years with no action, maybe we need to add a custom lib, like we did for a couple other things.

ebebbington commented 3 years ago

@kitsonk If this is something you (or the core team) decide to go with, i'm happy to try implement it as I of course have my own reasons for the issue to be fixed - it sounds simple enough, depending on if rust will be used ;)

ebebbington commented 3 years ago

I'll note that I'd have no clue where to start so it may well be i'm ill equipped to do so

kitsonk commented 3 years ago

Don't worry about it, the core team can address it once we have a chat about it.

ebebbington commented 3 years ago

Do you know if there is a hacky way to get around this for the time being? (not incl --no-check)

kitsonk commented 3 years ago

I believe this in your root module should work:

declare global {
  interface ReadableStream<R = any> {
    [Symbol.asyncIterator](options?: { preventCancel?: boolean; }): AsyncIterableIterator<R>;
  }
}
ebebbington commented 3 years ago

Thanks @kitsonk, and great to hear you've already done a PR!