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

ReadableStream.from not in documentation or types #21733

Closed
mdekstrand opened this issue Dec 29, 2023 · 4 comments
Closed

ReadableStream.from not in documentation or types #21733

mdekstrand opened this issue Dec 29, 2023 · 4 comments

Comments

@mdekstrand
Copy link

#19417 added the ReadableStream.from method, and various functions in std are marked as deprecated, but this method appears in neither the documentation nor the type definitions. It works, but code using it fails deno check.

@kt3k
Copy link
Member

kt3k commented Jan 2, 2024

What is your deno version? Do you modify the type settings? ReadableStream.from is defined in https://github.com/dsherret/deno/blob/26cf06ed9f5c0ffa42afff3dbe29533ddcb2fbf7/ext/web/lib.deno_web.d.ts#L815-L817 and it should pass type check with deno check with the default type settings.

@mdekstrand
Copy link
Author

I'm on Deno 1.39.1 with lib set to deno.window; if I remove the lib entirely from deno.json, it still fails to typecheck.

I do now see the from method displayed in the type in the documentation.

Here's the Deno error:

error: TS2339 [ERROR]: Property 'from' does not exist on type '{ new (underlyingSource: UnderlyingByteSource, strategy?: { highWaterMark?: number | undefined; } | undefined): ReadableStream<Uint8Array>; new <R = any>(underlyingSource: UnderlyingDefaultSource<...>, strategy?: QueuingStrategy<...> | undefined): ReadableStream<...>; new <R = any>(underlyingSource?: UnderlyingSourc...'.
let reader = ReadableStream.from(
                            ~~~~
    at file:///Users/michael/Documents/web/md.ekstrandom.net/tools/render.ts:43:29

However, when I try to create a minimal reproducing example, it does pass the typechecker, so it looks like something else is going on here. (Interestingly, my MRE typechecks with deno check at the CLI, but not in VSCode.)

Attempted MRE
import { CsvStringifyStream } from "std/csv/mod.ts";

let perfOut = await Deno.open("build/performance.csv", {
  create: true,
  write: true,
  truncate: true,
});
let recOut = new CsvStringifyStream({
  columns: ["name", "startTime", "duration", "detail"],
});
let reader = ReadableStream.from(
  performance.getEntriesByType("measure") as unknown as Record<string, unknown>[],
);
await reader.pipeThrough(recOut).pipeThrough(new TextEncoderStream()).pipeTo(perfOut.writable);

@BlackAsLight
Copy link

While it does seem to have type checking for the deno.window lib. Try literally any other lib, like deno.ns and it no longer exists.

ReadableStream.from(example())

function* example() {

}
{
	"compilerOptions": {
		"lib": [
			"dom",
			"deno.ns"
		]
	}
}

@crowlKats
Copy link
Member

Seems the dom library doesnt have the typings for ReadableStream.from: https://github.com/denoland/deno/blob/main/cli/tsc/dts/lib.dom.d.ts#L18507-L18512

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