Skip to content

Commit cbc2d23

Browse files
chore(internal): fix readablestream types in node 20
1 parent d412b5d commit cbc2d23

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

scripts/build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ npm exec tsc-multi
3737
# when building .mjs
3838
node scripts/utils/fix-index-exports.cjs
3939
cp tsconfig.dist-src.json dist/src/tsconfig.json
40-
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.ts
41-
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.mts
4240

4341
node scripts/utils/postprocess-files.cjs
4442

src/internal/shim-types.d.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/internal/shim-types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
/**
4+
* Shims for types that we can't always rely on being available globally.
5+
*
6+
* Note: these only exist at the type-level, there is no corresponding runtime
7+
* version for any of these symbols.
8+
*/
9+
10+
type NeverToAny<T> = T extends never ? any : T;
11+
12+
/** @ts-ignore */
13+
type _DOMReadableStream<R = any> = globalThis.ReadableStream<R>;
14+
15+
/** @ts-ignore */
16+
type _NodeReadableStream<R = any> = import('stream/web').ReadableStream<R>;
17+
18+
type _ConditionalNodeReadableStream<R = any> =
19+
typeof globalThis extends { ReadableStream: any } ? never : _NodeReadableStream<R>;
20+
21+
type _ReadableStream<R = any> = NeverToAny<
22+
| ([0] extends [1 & _DOMReadableStream<R>] ? never : _DOMReadableStream<R>)
23+
| ([0] extends [1 & _ConditionalNodeReadableStream<R>] ? never : _ConditionalNodeReadableStream<R>)
24+
>;
25+
26+
export type { _ReadableStream as ReadableStream };

src/internal/shims.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* messages in cases where an environment isn't fully supported.
88
*/
99

10-
import { type Fetch } from './builtin-types';
11-
import { type ReadableStream } from './shim-types';
10+
import type { Fetch } from './builtin-types';
11+
import type { ReadableStream } from './shim-types';
1212

1313
export function getDefaultFetch(): Fetch {
1414
if (typeof fetch !== 'undefined') {

0 commit comments

Comments
 (0)