denoland / deno

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

ReadableStream.from method fails type-checking in v1.45.0+ if you import openai package #24578

Closed Macil closed 1 month ago

Macil commented 1 month ago
import "npm:openai@^4.52.7";

const rs = ReadableStream.from([
  new Uint8Array([5, 6, 7]),
]);
> deno check .\main.ts
Check file:///E:/chris/Coding/deno-test/main.ts
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...'.
const rs = ReadableStream.from([
                          ~~~~
    at file:///E:/chris/Coding/deno-test/main.ts:3:27

This error does not happen if you remove the import.

This error does not happen in Deno 1.44.4. This error happens in 1.45.0 and above.

In VSCode, if I ctrl-click on ReadableStream in the code, I see that both lib.deno.web.d.ts and lib.dom.d.ts declare an interface and variable named ReadableStream, and polyfill.d.ts (from the "web-streams-polyfill" npm package, a dependency of the "openai" package) declares an interface named ReadableStream. If I comment out the import, then only the lib.deno.web.d.ts entry appears without the other two.

image

The variable declared by lib.dom.d.ts is missing the from method which is present in the variable declared by lib.deno.web.d.ts and there are some other inconsistencies in the new overloads. I think this problem would be fixed either by these two declarations being made consistent, or by the declaration in lib.dom.d.ts being removed entirely (as it's redundant, assuming it's the case that lib.deno.web.d.ts is always loaded).

petamoriken commented 1 month ago

We can patch lib.dom.d.ts such as #23893. I'll fix this issue.