e3181c2d77
This commit allows the users to import URLPattern from `next/server`, by defining a key that uses `global.URLPattern`. Why is this any good? or: why don't we add URLPattern to the global namespace? URLPattern is exposed as global on Edge Runtime _only_. This means that if we define a constructor in global namespace in our TypeScript definitions, people might have runtime errors in their Node.js functions. Importing from `next/server` enables users to get the constructor without risking in runtime errors and wrong type definitions. Keep in mind, that with the current implementation, we do not check if the constructor actually exists, but `next/server` shouldn't be imported in Node.js functions, AFAIK. ## Related - Fixes #38131 ## Bug - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
22 lines
1.2 KiB
TypeScript
22 lines
1.2 KiB
TypeScript
/**
|
|
* The type of `ReadableStreamBYOBReader` is not included in Typescript so we
|
|
* are declaring it inline to not have to worry about bundling.
|
|
*/
|
|
declare class ReadableStreamBYOBReader {
|
|
constructor(stream: ReadableStream<Uint8Array>)
|
|
get closed(): Promise<undefined>
|
|
cancel(reason?: any): Promise<void>
|
|
read<T extends ArrayBufferView>(
|
|
view: T
|
|
): Promise<{ done: false; value: T } | { done: true; value: T | undefined }>
|
|
releaseLock(): void
|
|
}
|
|
|
|
declare const ReadableStreamConstructor: typeof ReadableStream
|
|
declare const ReadableStreamBYOBReaderConstructor: typeof ReadableStreamBYOBReader
|
|
declare const ReadableStreamDefaultReaderConstructor: typeof ReadableStreamDefaultReader
|
|
declare const TransformStreamConstructor: typeof TransformStream
|
|
declare const WritableStreamConstructor: typeof WritableStream
|
|
declare const WritableStreamDefaultWriterConstructor: typeof WritableStreamDefaultWriter
|
|
|
|
export { ReadableStreamConstructor as ReadableStream, ReadableStreamBYOBReaderConstructor as ReadableStreamBYOBReader, ReadableStreamDefaultReaderConstructor as ReadableStreamDefaultReader, TransformStreamConstructor as TransformStream, WritableStreamConstructor as WritableStream, WritableStreamDefaultWriterConstructor as WritableStreamDefaultWriter };
|