deno icon indicating copy to clipboard operation
deno copied to clipboard

feat(ext/web): add typings for `ReadableStream.from`

Open Hajime-san opened this issue 1 year ago • 7 comments

fixes https://github.com/denoland/deno/issues/21981

This typing implementation goes well below.

/// <reference no-default-lib="true" />
/// <reference lib="deno.web" />

function* iterable() {
  yield 1;
  yield 2;
  yield 3;
}

const asyncIterable = (async function* () {
  yield "a";
  yield "b";
  yield "c";
})();

const stream = ReadableStream.from(iterable());

for await (const value of stream) {
  console.log(value);
}

const asyncStream = ReadableStream.from(asyncIterable);

for await (const value of asyncStream) {
  console.log(value);
}
  • https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/from_static

Hajime-san avatar Jan 29 '24 08:01 Hajime-san

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jan 29 '24 08:01 CLAassistant

ReadableStream.from is static method. It have already defined here:

https://github.com/denoland/deno/blob/aed5e4997df26c99a186fb9a5b18da3bbc594ed3/ext/web/lib.deno_web.d.ts#L804-L818

petamoriken avatar Jan 29 '24 11:01 petamoriken

@petamoriken Thank you for checking, and it's my mistake. It needs to implement typings to dom and webworker for lib option. I will fix later soon.

  • cli/tsc/dts/lib.webworker.d.ts
  • cli/tsc/dts/lib.dom.d.ts

Hajime-san avatar Jan 30 '24 02:01 Hajime-san

from for deno.web is already defined at line 815 https://github.com/denoland/deno/blob/345423cf7697326258ce8b32f681910f4a2f77de/ext/web/lib.deno_web.d.ts#L815

#21981 is about supporting from without dom type lib

kt3k avatar Jan 30 '24 03:01 kt3k

@kt3k Thank you for suggesting. I missed that cli/tsc/dts directory is following TypeScript repo, so it will be overwritten when its updated.

It seems to discuss that the way to provide typings.

For example, "Please use deno.web for lib compiler option" ...🤔

Hajime-san avatar Jan 30 '24 03:01 Hajime-san

For example, "Please use deno.web for lib compiler option" ...🤔

BTW deno.web is enabled by default. The issue #21981 happens because deno.web is explicitly replaced by dom type lib

kt3k avatar Jan 30 '24 03:01 kt3k

BTW deno.web is enabled by default.

I get it. Thank you.

Hajime-san avatar Jan 30 '24 03:01 Hajime-san

It seems that a little more focus should be given to internal design or interface about this problem.👀 Thanks to all contributors!

Hajime-san avatar Feb 08 '24 05:02 Hajime-san