edge-runtime icon indicating copy to clipboard operation
edge-runtime copied to clipboard

What's the intended source for the global types extended by @edge-runtime/types?

Open stainless-em opened this issue 11 months ago • 0 comments

Questions & Answers

@edge-runtime/types depends on types like Request, Response, File, etc existing in the global scope, but it doesn't import them from anywhere. @types/node and lib.webworker.d.ts conflict with @edge-runtime/types, and lib.dom.d.ts works but contains many definitions that will not be available at runtime. what configuration are users expected to use?

tsc output with no dom/webworker/node/etc types

tsconfig:

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": [],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "types": ["@edge-runtime/types"],
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": false
  }
}
$ pnpm tsc
node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/abort-controller.d.ts:1:50 - error TS2304: Cannot find name 'AbortController'.

1 declare const AbortControllerConstructor: typeof AbortController
                                                   ~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/abort-controller.d.ts:3:47 - error TS2304: Cannot find name 'DOMException'.

3 declare const DOMExceptionConstructor: typeof DOMException
                                                ~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/abort-controller.d.ts:9:34 - error TS2749: 'AbortSignal' refers to a value, but is being used as a type here. Did you mean 'typeof AbortSignal'?

9   timeout(milliseconds: number): AbortSignal
                                   ~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/abort-controller.d.ts:11:27 - error TS2749: 'AbortSignal' refers to a value, but is being used as a type here. Did you mean 'typeof AbortSignal'?

11   abort(reason?: string): AbortSignal
                             ~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:2:11 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

2   assert: Console['assert']
            ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:3:10 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

3   count: Console['count']
           ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:4:10 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

4   debug: Console['debug']
           ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:5:8 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

5   dir: Console['dir']
         ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:6:10 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

6   error: Console['error']
           ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:7:9 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

7   info: Console['info']
          ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:8:8 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

8   log: Console['log']
         ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:9:9 - error TS2552: Cannot find name 'Console'. Did you mean 'IConsole'?

9   time: Console['time']
          ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:10:12 - error TS2304: Cannot find name 'Console'.

10   timeEnd: Console['timeEnd']
              ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:11:12 - error TS2304: Cannot find name 'Console'.

11   timeLog: Console['timeLog']
              ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:12:10 - error TS2304: Cannot find name 'Console'.

12   trace: Console['trace']
            ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:13:9 - error TS2304: Cannot find name 'Console'.

13   warn: Console['warn']
           ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:1:23 - error TS2304: Cannot find name 'Crypto'.

1 declare const crypto: Crypto
                        ~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:3:41 - error TS2304: Cannot find name 'Crypto'.

3 declare const CryptoConstructor: typeof Crypto
                                          ~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:4:44 - error TS2304: Cannot find name 'CryptoKey'.

4 declare const CryptoKeyConstructor: typeof CryptoKey
                                             ~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:5:47 - error TS2304: Cannot find name 'SubtleCrypto'.

5 declare const SubtleCryptoConstructor: typeof SubtleCrypto
                                                ~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/events.d.ts:314:40 - error TS2304: Cannot find name 'Event'.

314 declare const EventConstructor: typeof Event
                                           ~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/events.d.ts:317:12 - error TS2304: Cannot find name 'Request'.

317   request: Request
               ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/events.d.ts:318:13 - error TS2304: Cannot find name 'Response'.

318   response: Response | null
                ~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/events.d.ts:320:24 - error TS2304: Cannot find name 'Request'.

320   constructor(request: Request)
                           ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/events.d.ts:321:25 - error TS2304: Cannot find name 'Response'.

321   respondWith(response: Response | Promise<Response>): void
                            ~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/events.d.ts:321:44 - error TS2304: Cannot find name 'Response'.

321   respondWith(response: Response | Promise<Response>): void
                                               ~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:1:42 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

1 declare class Request extends globalThis.Request {
                                           ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:2:21 - error TS2304: Cannot find name 'Headers'.

2   readonly headers: Headers
                      ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:6:43 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

6 declare class Response extends globalThis.Response {
                                            ~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:7:21 - error TS2304: Cannot find name 'Headers'.

7   readonly headers: Headers
                      ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:8:33 - error TS2304: Cannot find name 'ResponseInit'.

8   static json(data: any, init?: ResponseInit): Response
                                  ~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:11:50 - error TS2694: Namespace 'globalThis' has no exported member 'Request'.

11 type RequestInfo = string | Request | globalThis.Request
                                                    ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:12:31 - error TS2694: Namespace 'globalThis' has no exported member 'RequestInit'.

12 type RequestInit = globalThis.RequestInit
                                 ~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:18:39 - error TS2304: Cannot find name 'File'.

18 declare const FileConstructor: typeof File
                                         ~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:19:43 - error TS2304: Cannot find name 'FormData'.

19 declare const FormDataConstructor: typeof FormData
                                             ~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:20:44 - error TS2304: Cannot find name 'WebSocket'.

20 declare const WebSocketConstructor: typeof WebSocket
                                              ~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:21:42 - error TS2304: Cannot find name 'Headers'.

21 declare const HeadersConstructor: typeof Headers
                                            ~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:9:39 - error TS2304: Cannot find name 'Blob'.

9 declare const BlobConstructor: typeof Blob
                                        ~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:11:46 - error TS2304: Cannot find name 'TextEncoder'.

11 declare const TextEncoderConstructor: typeof TextEncoder
                                                ~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:12:46 - error TS2304: Cannot find name 'TextDecoder'.

12 declare const TextDecoderConstructor: typeof TextDecoder
                                                ~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:15:29 - error TS2304: Cannot find name 'atob'.

15 declare const _atob: typeof atob
                               ~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:16:29 - error TS2304: Cannot find name 'btoa'.

16 declare const _btoa: typeof btoa
                               ~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:23:23 - error TS2304: Cannot find name 'ReadableStream'.

23   constructor(stream: ReadableStream<Uint8Array>)
                         ~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:32:49 - error TS2304: Cannot find name 'ReadableStream'.

32 declare const ReadableStreamConstructor: typeof ReadableStream
                                                   ~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:34:62 - error TS2304: Cannot find name 'ReadableStreamDefaultReader'.

34 declare const ReadableStreamDefaultReaderConstructor: typeof ReadableStreamDefaultReader
                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:35:50 - error TS2304: Cannot find name 'TransformStream'.

35 declare const TransformStreamConstructor: typeof TransformStream
                                                    ~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:36:49 - error TS2304: Cannot find name 'WritableStream'.

36 declare const WritableStreamConstructor: typeof WritableStream
                                                   ~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:37:62 - error TS2304: Cannot find name 'WritableStreamDefaultWriter'.

37 declare const WritableStreamDefaultWriterConstructor: typeof WritableStreamDefaultWriter
                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:39:52 - error TS2304: Cannot find name 'TextDecoderStream'.

39 declare const TextDecoderStreamConstructor: typeof TextDecoderStream
                                                      ~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:40:52 - error TS2304: Cannot find name 'TextEncoderStream'.

40 declare const TextEncoderStreamConstructor: typeof TextEncoderStream
                                                      ~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:42:50 - error TS2304: Cannot find name 'structuredClone'.

42 declare const structuredCloneConstructor: typeof structuredClone
                                                    ~~~~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:44:46 - error TS2304: Cannot find name 'performance'.

44 declare const performanceConstructor: typeof performance
                                                ~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/url.d.ts:51:28 - error TS2304: Cannot find name 'URL'.

51 declare const _URL: typeof URL
                              ~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/url.d.ts:52:40 - error TS2304: Cannot find name 'URLSearchParams'.

52 declare const _URLSearchParams: typeof URLSearchParams
                                          ~~~~~~~~~~~~~~~


Found 54 errors in 7 files.

Errors  Files
     4  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/abort-controller.d.ts:1
    12  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/console.d.ts:2
     4  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:1
     6  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/events.d.ts:314
    11  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:1
    15  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/index.d.ts:9
     2  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/url.d.ts:51
tsc output with webworker types

tsconfig:

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["WebWorker"],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "types": ["@edge-runtime/types"],
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": false
  }
}

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/types/src/index.d.ts:14:9 - error TS2451: Cannot redeclare block-scoped variable 'FetchEvent'.

14   const FetchEvent: typeof Edge.FetchEvent
           ~~~~~~~~~~

  node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.webworker.d.ts:2925:11
    2925 interface FetchEvent extends ExtendableEvent {
                   ~~~~~~~~~~
    'FetchEvent' was also declared here.
  node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.webworker.d.ts:2940:13
    2940 declare var FetchEvent: {
                     ~~~~~~~~~~
    and here.

node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.webworker.d.ts:2925:11 - error TS2451: Cannot redeclare block-scoped variable 'FetchEvent'.

2925 interface FetchEvent extends ExtendableEvent {
               ~~~~~~~~~~

  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/types/src/index.d.ts:14:9
    14   const FetchEvent: typeof Edge.FetchEvent
               ~~~~~~~~~~
    'FetchEvent' was also declared here.

node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.webworker.d.ts:2940:13 - error TS2451: Cannot redeclare block-scoped variable 'FetchEvent'.

2940 declare var FetchEvent: {
                 ~~~~~~~~~~

  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/types/src/index.d.ts:14:9
    14   const FetchEvent: typeof Edge.FetchEvent
               ~~~~~~~~~~
    'FetchEvent' was also declared here.


Found 3 errors in 2 files.

Errors  Files
     1  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/types/src/index.d.ts:14
     2  node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.webworker.d.ts:2925
tsc output with node types

tsconfig:

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": [],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "types": ["@edge-runtime/types", "node"],
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": false
  }
}
node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:1:23 - error TS2304: Cannot find name 'Crypto'.

1 declare const crypto: Crypto
                        ~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:3:41 - error TS2552: Cannot find name 'Crypto'. Did you mean 'crypto'?

3 declare const CryptoConstructor: typeof Crypto
                                          ~~~~~~

  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:1:15
    1 declare const crypto: Crypto
                    ~~~~~~
    'crypto' is declared here.

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:4:44 - error TS2552: Cannot find name 'CryptoKey'. Did you mean 'crypto'?

4 declare const CryptoKeyConstructor: typeof CryptoKey
                                             ~~~~~~~~~

  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:1:15
    1 declare const crypto: Crypto
                    ~~~~~~
    'crypto' is declared here.

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:5:47 - error TS2304: Cannot find name 'SubtleCrypto'.

5 declare const SubtleCryptoConstructor: typeof SubtleCrypto
                                                ~~~~~~~~~~~~

node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:3:12 - error TS2416: Property 'duplex' in type 'Request' is not assignable to the same property in base type 'Request'.
  Type 'string' is not assignable to type '"half"'.

3   readonly duplex: string
             ~~~~~~


Found 5 errors in 2 files.

Errors  Files
     4  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/crypto.d.ts:1
     1  node_modules/.pnpm/@[email protected]/node_modules/@edge-runtime/primitives/types/fetch.d.ts:3

stainless-em avatar Jan 27 '25 15:01 stainless-em