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

Type checking regressions related to dom types upgrading from 0.22.0 to 0.24.0 #165

Closed
kitsonk opened this issue Jun 3, 2022 · 6 comments

Comments

@kitsonk
Copy link

kitsonk commented Jun 3, 2022

I tried updating from 0.22.0 to 0.24.0 and get all sort of regression issues. Using the following build config:

{
    entryPoints: ["./mod.ts"],
    outDir: "./npm",
    mappings: {
      "./http_server_native.ts": "./http_server_node.ts",
    },
    shims: {
      blob: true,
      crypto: true,
      deno: true,
      undici: true,
      custom: [{
        package: {
          name: "stream/web",
        },
        globalNames: ["ReadableStream", "TransformStream"],
      }, {
        module: "./node_shims.ts",
        globalNames: ["ErrorEvent"],
      }],
    },
    test: true,
    compilerOptions: {
      importHelpers: true,
      target: "ES2021",
    },
    package: {
      name: "@oakserver/oak",
      version: Deno.args[0],
      description: "A middleware framework for handling HTTP requests",
      license: "MIT",
      engines: {
        node: ">=16.5.0 <18",
      },
      repository: {
        type: "git",
        url: "git+https://github.com/oakserver/oak.git",
      },
      bugs: {
        url: "https://github.com/oakserver/oak/issues",
      },
      dependencies: {
        "tslib": "~2.3.1",
      },
      devDependencies: {
        "@types/node": "^16",
      },
    },
  }
And get all sorts of type issues:
npm/src/application.ts:76:11 - error TS2304: Cannot find name 'ErrorEventInit'.

76   extends ErrorEventInit {
             ~~~~~~~~~~~~~~
npm/src/application.ts:76:11 - error TS4022: 'extends' clause of exported interface 'ApplicationErrorEventInit' has or is using private name 'ErrorEventInit'.

76   extends ErrorEventInit {
             ~~~~~~~~~~~~~~
npm/src/application.ts:92:46 - error TS2304: Cannot find name 'EventInit'.

92 interface ApplicationListenEventInit extends EventInit {
                                                ~~~~~~~~~
npm/src/application.ts:92:46 - error TS4022: 'extends' clause of exported interface 'ApplicationListenEventInit' has or is using private name 'EventInit'.

92 interface ApplicationListenEventInit extends EventInit {
                                                ~~~~~~~~~
npm/src/application.ts:215:45 - error TS2304: Cannot find name 'Event'.

215 export class ApplicationListenEvent extends Event {
                                                ~~~~~
npm/src/application.ts:215:45 - error TS4020: 'extends' clause of exported class 'ApplicationListenEvent' has or is using private name 'Event'.

215 export class ApplicationListenEvent extends Event {
                                                ~~~~~
npm/src/application.ts:261:11 - error TS2304: Cannot find name 'EventTarget'.

261   extends EventTarget {
              ~~~~~~~~~~~
npm/src/application.ts:261:11 - error TS4020: 'extends' clause of exported class 'Application' has or is using private name 'EventTarget'.

261   extends EventTarget {
              ~~~~~~~~~~~
npm/src/application.ts:355:10 - error TS2339: Property 'dispatchEvent' does not exist on type 'Application<AS>'.

355     this.dispatchEvent(new ApplicationErrorEvent({ context, message, error }));
             ~~~~~~~~~~~~~
npm/src/application.ts:355:61 - error TS2345: Argument of type '{ context: Context<AS, Record<string, any>>; message: any; error: any; }' is not assignable to parameter of type 'ApplicationErrorEventInit<AS, Record<string, any>>'.
  Object literal may only specify known properties, and 'message' does not exist in type 'ApplicationErrorEventInit<AS, Record<string, any>>'.

355     this.dispatchEvent(new ApplicationErrorEvent({ context, message, error }));
                                                                ~~~~~~~
npm/src/application.ts:433:25 - error TS2304: Cannot find name 'AddEventListenerOptions'.

433     options?: boolean | AddEventListenerOptions,
                            ~~~~~~~~~~~~~~~~~~~~~~~
npm/src/application.ts:433:25 - error TS4073: Parameter 'options' of public method from exported class has or is using private name 'AddEventListenerOptions'.

433     options?: boolean | AddEventListenerOptions,
                            ~~~~~~~~~~~~~~~~~~~~~~~
npm/src/application.ts:440:25 - error TS2304: Cannot find name 'AddEventListenerOptions'.

440     options?: boolean | AddEventListenerOptions,
                            ~~~~~~~~~~~~~~~~~~~~~~~
npm/src/application.ts:440:25 - error TS4073: Parameter 'options' of public method from exported class has or is using private name 'AddEventListenerOptions'.

440     options?: boolean | AddEventListenerOptions,
                            ~~~~~~~~~~~~~~~~~~~~~~~
npm/src/application.ts:446:15 - error TS2304: Cannot find name 'EventListenerOrEventListenerObject'.

446     listener: EventListenerOrEventListenerObject | null,
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/application.ts:447:25 - error TS2304: Cannot find name 'AddEventListenerOptions'.

447     options?: boolean | AddEventListenerOptions,
                            ~~~~~~~~~~~~~~~~~~~~~~~
npm/src/application.ts:538:14 - error TS2339: Property 'addEventListener' does not exist on type 'AbortSignal'.

538       signal.addEventListener("abort", () => {
                 ~~~~~~~~~~~~~~~~
npm/src/application.ts:550:10 - error TS2339: Property 'dispatchEvent' does not exist on type 'Application<AS>'.

550     this.dispatchEvent(
             ~~~~~~~~~~~~~
npm/src/application.ts:568:12 - error TS2339: Property 'dispatchEvent' does not exist on type 'Application<AS>'.

568       this.dispatchEvent(
               ~~~~~~~~~~~~~
npm/src/application.ts:569:37 - error TS2345: Argument of type '{ message: string; error: any; }' is not assignable to parameter of type 'ApplicationErrorEventInit<State, State>'.
  Object literal may only specify known properties, and 'message' does not exist in type 'ApplicationErrorEventInit<State, State>'.

569         new ApplicationErrorEvent({ message, error }),
                                        ~~~~~~~
npm/src/body.ts:186:21 - error TS2304: Cannot find name 'TextDecoder'.

186 const decoder = new TextDecoder();
                        ~~~~~~~~~~~
npm/src/body_test.ts:17:21 - error TS2304: Cannot find name 'TextDecoder'.

17 const decoder = new TextDecoder();
                       ~~~~~~~~~~~
npm/src/buf_reader_test.ts:10:21 - error TS2304: Cannot find name 'TextDecoder'.

10 const decoder = new TextDecoder();
                       ~~~~~~~~~~~
npm/src/content_disposition.ts:103:27 - error TS2304: Cannot find name 'TextDecoder'.

103       const decoder = new TextDecoder(encoding, { fatal: true });
                              ~~~~~~~~~~~
npm/src/context.ts:67:13 - error TS2304: Cannot find name 'WebSocket'.

67   #socket?: WebSocket;
               ~~~~~~~~~
npm/src/context.ts:108:17 - error TS2304: Cannot find name 'WebSocket'.

108   get socket(): WebSocket | undefined {
                    ~~~~~~~~~
npm/src/context.ts:108:17 - error TS4043: Return type of public getter 'socket' from exported class has or is using private name 'WebSocket'.

108   get socket(): WebSocket | undefined {
                    ~~~~~~~~~
npm/src/context.ts:233:47 - error TS2304: Cannot find name 'WebSocket'.

233   upgrade(options?: UpgradeWebSocketOptions): WebSocket {
                                                  ~~~~~~~~~
npm/src/context.ts:233:47 - error TS4055: Return type of public method from exported class has or is using private name 'WebSocket'.

233   upgrade(options?: UpgradeWebSocketOptions): WebSocket {
                                                  ~~~~~~~~~
npm/src/context_test.ts:66:29 - error TS2304: Cannot find name 'WebSocket'.

66 const mockWebSocket = {} as WebSocket;
                               ~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/encoding/base64.ts:78:11 - error TS2304: Cannot find name 'TextEncoder'.

78     ? new TextEncoder().encode(data)
             ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/buffer.ts:470:16 - error TS2304: Cannot find name 'TextDecoder'.

470     return new TextDecoder().decode(buffer);
                   ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/buffer.ts:986:23 - error TS2304: Cannot find name 'TextEncoder'.

986   const encoder = new TextEncoder();
                          ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/buffer.ts:987:23 - error TS2304: Cannot find name 'TextDecoder'.

987   const decoder = new TextDecoder(decoderOpts?.encoding, decoderOpts);
                          ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/buffer.ts:1004:23 - error TS2304: Cannot find name 'TextDecoder'.

1004   const decoder = new TextDecoder(decoderOpts?.encoding, decoderOpts);
                           ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/readers.ts:14:15 - error TS2304: Cannot find name 'TextEncoder'.

14     super(new TextEncoder().encode(s).buffer);
                 ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/writers.ts:6:21 - error TS2304: Cannot find name 'TextDecoder'.

6 const decoder = new TextDecoder();
                      ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/writers.ts:15:19 - error TS2304: Cannot find name 'TextEncoder'.

15     const c = new TextEncoder().encode(base);
                     ~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/io/writers.ts:42:5 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

42     return this.#cache;
       ~~~~~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:67:17 - error TS2304: Cannot find name 'WritableStreamDefaultWriter'.

67   streamWriter: WritableStreamDefaultWriter<Uint8Array>,
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:67:17 - error TS4078: Parameter 'streamWriter' of exported function has or is using private name 'WritableStreamDefaultWriter'.

67   streamWriter: WritableStreamDefaultWriter<Uint8Array>,
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:80:17 - error TS2304: Cannot find name 'ReadableStreamDefaultReader'.

80   streamReader: ReadableStreamDefaultReader<Uint8Array>,
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:80:17 - error TS4078: Parameter 'streamReader' of exported function has or is using private name 'ReadableStreamDefaultReader'.

80   streamReader: ReadableStreamDefaultReader<Uint8Array>,
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:113:4 - error TS2304: Cannot find name 'WritableStream'.

113 ): WritableStream<Uint8Array> {
       ~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:113:4 - error TS4060: Return type of exported function has or is using private name 'WritableStream'.

113 ): WritableStream<Uint8Array> {
       ~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:116:14 - error TS2304: Cannot find name 'WritableStream'.

116   return new WritableStream({
                 ~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:117:17 - error TS7006: Parameter 'chunk' implicitly has an 'any' type.

117     async write(chunk, controller) {
                    ~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:117:24 - error TS7006: Parameter 'controller' implicitly has an 'any' type.

117     async write(chunk, controller) {
                           ~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:226:22 - error TS2304: Cannot find name 'QueuingStrategy'.

226   writableStrategy?: QueuingStrategy<I>,
                         ~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:226:22 - error TS4078: Parameter 'writableStrategy' of exported function has or is using private name 'QueuingStrategy'.

226   writableStrategy?: QueuingStrategy<I>,
                         ~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:227:22 - error TS2304: Cannot find name 'QueuingStrategy'.

227   readableStrategy?: QueuingStrategy<O>,
                         ~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:227:22 - error TS4078: Parameter 'readableStrategy' of exported function has or is using private name 'QueuingStrategy'.

227   readableStrategy?: QueuingStrategy<O>,
                         ~~~~~~~~~~~~~~~
npm/src/etag.ts:45:21 - error TS2304: Cannot find name 'TextEncoder'.

45 const encoder = new TextEncoder();
                       ~~~~~~~~~~~
npm/src/etag.ts:56:74 - error TS2345: Argument of type 'string | Uint8Array' is not assignable to parameter of type 'BufferSource'.
  Type 'string' is not assignable to type 'BufferSource'.

56   const hash = base64.encode(await dntShim.crypto.subtle.digest("SHA-1", entity))
                                                                            ~~~~~~
npm/src/etag_test.ts:41:21 - error TS2304: Cannot find name 'TextEncoder'.

41 const encoder = new TextEncoder();
                       ~~~~~~~~~~~
npm/src/headers.ts:10:21 - error TS2304: Cannot find name 'TextDecoder'.

10 const decoder = new TextDecoder();
                       ~~~~~~~~~~~
npm/src/headers_test.ts:33:22 - error TS2304: Cannot find name 'TextEncoder'.

33       new Buffer(new TextEncoder().encode(fixture)),
                        ~~~~~~~~~~~
npm/src/headers_test.ts:42:11 - error TS2304: Cannot find name 'TextDecoder'.

42       new TextDecoder().decode((await body.readLine())?.bytes),
             ~~~~~~~~~~~
npm/src/http_server_native_request.ts:130:47 - error TS2304: Cannot find name 'WebSocket'.

130   upgrade(options?: UpgradeWebSocketOptions): WebSocket {
                                                  ~~~~~~~~~
npm/src/http_server_native_request.ts:130:47 - error TS4055: Return type of public method from exported class has or is using private name 'WebSocket'.

130   upgrade(options?: UpgradeWebSocketOptions): WebSocket {
                                                  ~~~~~~~~~
npm/src/middleware/proxy_test.ts:12:21 - error TS2304: Cannot find name 'TextDecoder'.

12 const decoder = new TextDecoder();
                       ~~~~~~~~~~~
npm/src/multipart.ts:12:21 - error TS2304: Cannot find name 'TextDecoder'.

12 const decoder = new TextDecoder();
                       ~~~~~~~~~~~
npm/src/multipart.ts:13:21 - error TS2304: Cannot find name 'TextEncoder'.

13 const encoder = new TextEncoder();
                       ~~~~~~~~~~~
npm/src/multipart_test.ts:20:21 - error TS2304: Cannot find name 'TextEncoder'.

20 const encoder = new TextEncoder();
                       ~~~~~~~~~~~
npm/src/node_shims.ts:3:33 - error TS2304: Cannot find name 'Event'.

3 export class ErrorEvent extends Event {
                                  ~~~~~
npm/src/node_shims.ts:3:33 - error TS4020: 'extends' clause of exported class 'ErrorEvent' has or is using private name 'Event'.

3 export class ErrorEvent extends Event {
                                  ~~~~~
npm/src/node_shims.ts:28:44 - error TS2304: Cannot find name 'ErrorEventInit'.

28   constructor(type: string, eventInitDict: ErrorEventInit = {}) {
                                              ~~~~~~~~~~~~~~
npm/src/node_shims.ts:28:44 - error TS4063: Parameter 'eventInitDict' of constructor from exported class has or is using private name 'ErrorEventInit'.

28   constructor(type: string, eventInitDict: ErrorEventInit = {}) {
                                              ~~~~~~~~~~~~~~
npm/src/range.ts:99:21 - error TS2304: Cannot find name 'TextEncoder'.

99 const encoder = new TextEncoder();
                       ~~~~~~~~~~~
npm/src/range_test.ts:81:25 - error TS2304: Cannot find name 'TextEncoder'.

81     const content = new TextEncoder().encode("hello deno");
                           ~~~~~~~~~~~
npm/src/range_test.ts:91:25 - error TS2304: Cannot find name 'TextEncoder'.

91     const content = new TextEncoder().encode("hello deno");
                           ~~~~~~~~~~~
npm/src/range_test.ts:148:25 - error TS2304: Cannot find name 'TextEncoder'.

148     const encoder = new TextEncoder();
                            ~~~~~~~~~~~
npm/src/range_test.ts:162:25 - error TS2304: Cannot find name 'TextDecoder'.

162     const decoder = new TextDecoder();
                            ~~~~~~~~~~~
npm/src/range_test.ts:175:25 - error TS2304: Cannot find name 'TextEncoder'.

175     const encoder = new TextEncoder();
                            ~~~~~~~~~~~
npm/src/range_test.ts:189:25 - error TS2304: Cannot find name 'TextDecoder'.

189     const decoder = new TextDecoder();
                            ~~~~~~~~~~~
npm/src/response_test.ts:122:25 - error TS2304: Cannot find name 'TextEncoder'.

122     response.body = new TextEncoder().encode("Hello world!");
                            ~~~~~~~~~~~
npm/src/server_sent_event.ts:8:21 - error TS2304: Cannot find name 'TextEncoder'.

8 const encoder = new TextEncoder();
                      ~~~~~~~~~~~
npm/src/server_sent_event.ts:12:46 - error TS2304: Cannot find name 'EventInit'.

12 export interface ServerSentEventInit extends EventInit {
                                                ~~~~~~~~~
npm/src/server_sent_event.ts:12:46 - error TS4022: 'extends' clause of exported interface 'ServerSentEventInit' has or is using private name 'EventInit'.

12 export interface ServerSentEventInit extends EventInit {
                                                ~~~~~~~~~
npm/src/server_sent_event.ts:41:26 - error TS2304: Cannot find name 'Event'.

41 class CloseEvent extends Event {
                            ~~~~~
npm/src/server_sent_event.ts:41:26 - error TS4020: 'extends' clause of exported class 'CloseEvent' has or is using private name 'Event'.

41 class CloseEvent extends Event {
                            ~~~~~
npm/src/server_sent_event.ts:42:26 - error TS2304: Cannot find name 'EventInit'.

42   constructor(eventInit: EventInit) {
                            ~~~~~~~~~
npm/src/server_sent_event.ts:42:26 - error TS4063: Parameter 'eventInit' of constructor from exported class has or is using private name 'EventInit'.

42   constructor(eventInit: EventInit) {
                            ~~~~~~~~~
npm/src/server_sent_event.ts:72:38 - error TS2304: Cannot find name 'Event'.

72 export class ServerSentEvent extends Event {
                                        ~~~~~
npm/src/server_sent_event.ts:72:38 - error TS4020: 'extends' clause of exported class 'ServerSentEvent' has or is using private name 'Event'.

72 export class ServerSentEvent extends Event {
                                        ~~~~~
npm/src/server_sent_event.ts:135:48 - error TS2304: Cannot find name 'EventTarget'.

135 export interface ServerSentEventTarget extends EventTarget {
                                                   ~~~~~~~~~~~
npm/src/server_sent_event.ts:135:48 - error TS4022: 'extends' clause of exported interface 'ServerSentEventTarget' has or is using private name 'EventTarget'.

135 export interface ServerSentEventTarget extends EventTarget {
                                                   ~~~~~~~~~~~
npm/src/server_sent_event.ts:217:38 - error TS2304: Cannot find name 'EventTarget'.

217 export class SSEStreamTarget extends EventTarget
                                         ~~~~~~~~~~~
npm/src/server_sent_event.ts:217:38 - error TS4020: 'extends' clause of exported class 'SSEStreamTarget' has or is using private name 'EventTarget'.

217 export class SSEStreamTarget extends EventTarget
                                         ~~~~~~~~~~~
npm/src/server_sent_event.ts:221:17 - error TS2304: Cannot find name 'ReadableStreamDefaultController'.

221   #controller?: ReadableStreamDefaultController<Uint8Array>;
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/server_sent_event.ts:233:23 - error TS2339: Property 'dispatchEvent' does not exist on type 'Application<Record<string, any>>'.

233     this.#context.app.dispatchEvent(errorEvent);
                          ~~~~~~~~~~~~~
npm/src/server_sent_event.ts:285:10 - error TS2339: Property 'addEventListener' does not exist on type 'SSEStreamTarget'.

285     this.addEventListener("close", () => {
             ~~~~~~~~~~~~~~~~
npm/src/server_sent_event_test.ts:26:18 - error TS2304: Cannot find name 'EventTarget'.

26   appTarget: new EventTarget(),
                    ~~~~~~~~~~~
npm/src/server_sent_event_test.ts:34:23 - error TS2304: Cannot find name 'EventTarget'.

34   env.appTarget = new EventTarget();
                         ~~~~~~~~~~~
npm/src/server_sent_event_test.ts:38:6 - error TS7006: Parameter 'evt' implicitly has an 'any' type.

38     (evt) => {
        ~~~
npm/src/server_sent_event_test.ts:59:22 - error TS2339: Property 'type' does not exist on type 'ServerSentEvent'.

59     assertEquals(evt.type, "message");
                        ~~~~
npm/src/server_sent_event_test.ts:70:22 - error TS2339: Property 'type' does not exist on type 'ServerSentEvent'.

70     assertEquals(evt.type, "ping");
                        ~~~~
npm/src/server_sent_event_test.ts:81:22 - error TS2339: Property 'type' does not exist on type 'ServerSentEvent'.

81     assertEquals(evt.type, "ping");
                        ~~~~
npm/src/server_sent_event_test.ts:95:22 - error TS2339: Property 'type' does not exist on type 'ServerSentEvent'.

95     assertEquals(evt.type, "ping");
                        ~~~~
npm/src/server_sent_event_test.ts:108:22 - error TS2339: Property 'type' does not exist on type 'ServerSentEvent'.

108     assertEquals(evt.type, "__message");
                         ~~~~
npm/src/server_sent_event_test.ts:236:9 - error TS2339: Property 'addEventListener' does not exist on type 'SSEStreamTarget'.

236     sse.addEventListener("close", () => {
            ~~~~~~~~~~~~~~~~
npm/src/server_sent_event_test.ts:239:9 - error TS2339: Property 'addEventListener' does not exist on type 'SSEStreamTarget'.

239     sse.addEventListener("error", () => {
            ~~~~~~~~~~~~~~~~
npm/src/structured_clone.ts:142:17 - error TS2304: Cannot find name 'DOMException'.

142       throw new DOMException("Uncloneable value in stream", "DataCloneError");
                    ~~~~~~~~~~~~
npm/src/types.d.d.ts:94:48 - error TS2304: Cannot find name 'WebSocket'.

94   upgrade?(options?: UpgradeWebSocketOptions): WebSocket;
                                                  ~~~~~~~~~
npm/src/types.d.d.ts:120:11 - error TS2304: Cannot find name 'WebSocket'.

120   socket: WebSocket;
              ~~~~~~~~~
npm/src/util.ts:378:21 - error TS2304: Cannot find name 'TransformStreamDefaultController'.

378         controller: TransformStreamDefaultController<Uint8Array>,
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm/src/util.ts:420:20 - error TS2304: Cannot find name 'TextEncoder'.

420       encoder: new TextEncoder(),
                       ~~~~~~~~~~~
npm/src/util.ts:432:21 - error TS2304: Cannot find name 'TextEncoder'.

432 const encoder = new TextEncoder();
                        ~~~~~~~~~~~
npm/src/util.ts:448:10 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(format: "jwk", keyData: JsonWebKey, algorithm: AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<...>', gave the following error.
    Argument of type '"raw"' is not assignable to parameter of type '"jwk"'.
  Overload 2 of 2, '(format: "raw" | "spki" | "pkcs8", keyData: BufferSource, algorithm: AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<...>', gave the following error.
    Argument of type 'Key' is not assignable to parameter of type 'BufferSource'.
      Type 'string' is not assignable to type 'BufferSource'.

448   return dntShim.crypto.subtle.importKey(
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
449     "raw",
    ~~~~~~~~~~
... 
456     ["sign", "verify"],
    ~~~~~~~~~~~~~~~~~~~~~~~
457   );
    ~~~

npm/src/util.ts:466:50 - error TS2345: Argument of type 'Data' is not assignable to parameter of type 'BufferSource'.
  Type 'string' is not assignable to type 'BufferSource'.

466   return dntShim.crypto.subtle.sign("HMAC", key, data);
                                                     ~~~~

I'm not sure what has changed... it is non-obvious to me.

@dsherret
Copy link
Member

dsherret commented Jun 3, 2022

@kitsonk what happens when you add back DOM types? See code block here: https://github.com/denoland/dnt#dom-types (sorry, I’m on my phone)

@kitsonk
Copy link
Author

kitsonk commented Jun 3, 2022

Ok that goes from 110 down to 4, which were somewhat similar to 0.22.0, which made me try to update:

The first one is a regression that CLI had with 4.7 and the polyfill types need to be changed to work. I am seeing the others in 0.22.0 as well as 0.24.0. I use web/stream, so I tried updating the @types/node to ^17 to see if it was related to that, but it isn't.

npm/src/_dnt.polyfills.ts:3:5 - error TS2717: Subsequent property declarations must have the same type.  Property 'cause' must be of type 'Error | undefined', but here has type 'any'.

3     cause?: any;
      ~~~~~

  ../../../../node_modules/typescript/lib/lib.es2022.error.d.ts:2:54
    2 interface ErrorOptions{cause?:Error;}interface Error{cause?:Error;}interface ErrorConstructor{new(message?:string,options?:ErrorOptions):Error;(message?:string,options?:ErrorOptions):Error;}interface EvalErrorConstructor{new(message?:string,options?:ErrorOptions):EvalError;(message?:string,options?:ErrorOptions):EvalError;}interface RangeErrorConstructor{new(message?:string,options?:ErrorOptions):RangeError;(message?:string,options?:ErrorOptions):RangeError;}interface ReferenceErrorConstructor{new(message?:string,options?:ErrorOptions):ReferenceError;(message?:string,options?:ErrorOptions):ReferenceError;}interface SyntaxErrorConstructor{new(message?:string,options?:ErrorOptions):SyntaxError;(message?:string,options?:ErrorOptions):SyntaxError;}interface TypeErrorConstructor{new(message?:string,options?:ErrorOptions):TypeError;(message?:string,options?:ErrorOptions):TypeError;}interface URIErrorConstructor{new(message?:string,options?:ErrorOptions):URIError;(message?:string,options?:ErrorOptions):URIError;}interface AggregateErrorConstructor{new(errors:Iterable<any>,message?:string,options?:ErrorOptions):AggregateError;(errors:Iterable<any>,message?:string,options?:ErrorOptions):AggregateError;}
                                                           ~~~~~
    'cause' was also declared here.
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:232:52 - error TS2345: Argument of type 'QueuingStrategy<I> | undefined' is not assignable to parameter of type 'import("stream/web").QueuingStrategy<I> | undefined'.
  Type 'QueuingStrategy<I>' is not assignable to type 'import("stream/web").QueuingStrategy<I>'.
    Types of property 'size' are incompatible.
      Type 'QueuingStrategySize<I> | undefined' is not assignable to type 'import("stream/web").QueuingStrategySize<I> | undefined'.
        Type 'QueuingStrategySize<I>' is not assignable to type 'import("stream/web").QueuingStrategySize<I>'.
          Types of parameters 'chunk' and 'chunk' are incompatible.
            Type 'I | undefined' is not assignable to type 'I'.
              'I' could be instantiated with an arbitrary type which could be unrelated to 'I | undefined'.

232   } = new dntShim.TransformStream<I, I>(undefined, writableStrategy);
                                                       ~~~~~~~~~~~~~~~~
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:240:5 - error TS2322: Type 'ReadableStream<Uint8Array>' is not assignable to type 'ReadableStream<O>'.
  Type 'Uint8Array' is not assignable to type 'O'.
    'O' could be instantiated with an arbitrary type which could be unrelated to 'Uint8Array'.

240     readable: new dntShim.ReadableStream<O>({
        ~~~~~~~~

  npm/node_modules/@types/node/stream/web.d.ts:225:18
    225         readonly readable: ReadableStream<O>;
                         ~~~~~~~~
    The expected type comes from property 'readable' which is declared here on type 'TransformStream<I, O>'
npm/src/deps/deno.land/std@0.142.0/streams/conversion.ts:269:8 - error TS2345: Argument of type 'QueuingStrategy<O> | undefined' is not assignable to parameter of type 'import("stream/web").QueuingStrategy<O> | undefined'.
  Type 'QueuingStrategy<O>' is not assignable to type 'import("stream/web").QueuingStrategy<O>'.

269     }, readableStrategy),
           ~~~~~~~~~~~~~~~~

error: Uncaught (in promise) Error: Had 4 diagnostics.
      throw new Error(`Had ${diagnostics.length} diagnostics.`);
            ^
    at build (https://deno.land/x/dnt@0.24.0/mod.ts:282:13)
    at async start (file:///Users/kitsonk/github/oak/_build_npm.ts:19:3)

@dsherret
Copy link
Member

dsherret commented Jun 3, 2022

Should be slightly better in 0.25.0. I will investigate the other typings soon (next week probably).

@bermi
Copy link

bermi commented Jun 7, 2022

@dsherret I'm getting similar errors using 0.25.2.

@harrysolovay
Copy link

I am as well.

target/npm/src/rpc/Error.ts:9:31 - error TS4063: Parameter 'event' of constructor from exported class has or is using private name 'Event'.

9   constructor(readonly event: Event) {
                                ~~~~~
target/npm/src/rpc/Error.ts:19:31 - error TS4063: Parameter 'event' of constructor from exported class has or is using private name 'Event'.

19   constructor(readonly event: Event) {
                                 ~~~~~

error: Uncaught (in promise) Error: Had 2 emit diagnostics.
      throw new Error(`Had ${emitResult.diagnostics.length} emit diagnostics.`);

@dsherret dsherret changed the title Strange type checking regressions Type checking regressions related to dom types upgrading from 0.22.0 to 0.24.0 Jun 15, 2022
@dsherret
Copy link
Member

dsherret commented Jun 15, 2022

@kitsonk the other issues seem related to the 0.142.0 std upgrade. It needed a QueuingStrategy shim from "streams/web". I'm going to open a PR on oak.

Everyone else, in most cases the errors can be fixed by enabling dom types https://github.com/denoland/dnt#dom-types or by adding a @types/node package as a dev dependency in the package object provided to the build function. If it's still not fixed, then please open a specific issue with a reproduction (or link to a branch in a repo that reproduces the issue).

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