From 5d807c71f65bb33e9dfec1465d0235cef7a6a667 Mon Sep 17 00:00:00 2001
From: Khafra <42794878+KhafraDev@users.noreply.github.com>
Date: Mon, 7 Nov 2022 14:31:41 -0500
Subject: [PATCH 1/5] fix: add fallback types for node v16
---
package.json | 3 +--
types/filereader.d.ts | 3 ++-
types/patch.d.ts | 21 +++++++++++++++++++++
3 files changed, 24 insertions(+), 3 deletions(-)
create mode 100644 types/patch.d.ts
diff --git a/package.json b/package.json
index c82f1a6e5ab..b2708018e58 100644
--- a/package.json
+++ b/package.json
@@ -116,8 +116,7 @@
"compilerOptions": {
"esModuleInterop": true,
"lib": [
- "esnext",
- "DOM"
+ "esnext"
]
}
},
diff --git a/types/filereader.d.ts b/types/filereader.d.ts
index 8bd7e15c242..902a6bcf87c 100644
--- a/types/filereader.d.ts
+++ b/types/filereader.d.ts
@@ -1,6 +1,7 @@
///
import { Blob } from 'buffer'
+import { DOMException, Event, EventInit, EventTarget } from './patch'
export declare class FileReader extends EventTarget {
constructor ()
@@ -46,4 +47,4 @@ export declare class ProgressEvent extends Event {
readonly lengthComputable: boolean
readonly loaded: number
readonly total: number
-}
\ No newline at end of file
+}
diff --git a/types/patch.d.ts b/types/patch.d.ts
new file mode 100644
index 00000000000..109a0f21b4f
--- /dev/null
+++ b/types/patch.d.ts
@@ -0,0 +1,21 @@
+///
+
+// See https://github.com/nodejs/undici/issues/1740
+
+export type DOMException = typeof globalThis extends { DOMException: infer T }
+ ? T
+ : any
+
+export type EventTarget = typeof globalThis extends { EventTarget: infer T }
+ ? T
+ : any
+
+export type Event = typeof globalThis extends { Event: infer T }
+ ? T
+ : any
+
+export interface EventInit {
+ bubbles?: boolean
+ cancelable?: boolean
+ composed?: boolean
+}
From cccf3f5a91580bcda74319cda77a972415d3acbb Mon Sep 17 00:00:00 2001
From: Khafra <42794878+KhafraDev@users.noreply.github.com>
Date: Mon, 7 Nov 2022 14:46:32 -0500
Subject: [PATCH 2/5] fix: try new approach
---
types/patch.d.ts | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/types/patch.d.ts b/types/patch.d.ts
index 109a0f21b4f..abd04dae037 100644
--- a/types/patch.d.ts
+++ b/types/patch.d.ts
@@ -6,13 +6,43 @@ export type DOMException = typeof globalThis extends { DOMException: infer T }
? T
: any
-export type EventTarget = typeof globalThis extends { EventTarget: infer T }
+export type EventTarget = typeof globalThis extends { EventTarget: { prototype: infer T } }
? T
- : any
+ : {
+ addEventListener(
+ type: string,
+ listener: EventListener | EventListenerObject,
+ options?: AddEventListenerOptions | boolean,
+ ): void
+ dispatchEvent(event: Event): boolean
+ removeEventListener(
+ type: string,
+ listener: EventListener | EventListenerObject,
+ options?: EventListenerOptions | boolean,
+ ): void
+ }
-export type Event = typeof globalThis extends { Event: infer T }
+export type Event = typeof globalThis extends { Event: { prototype: infer T } }
? T
- : any
+ : {
+ readonly bubbles: boolean
+ cancelBubble: () => void
+ readonly cancelable: boolean
+ readonly composed: boolean
+ composedPath(): [EventTarget?]
+ readonly currentTarget: EventTarget | null
+ readonly defaultPrevented: boolean
+ readonly eventPhase: 0 | 2
+ readonly isTrusted: boolean
+ preventDefault(): void
+ returnValue: boolean
+ readonly srcElement: EventTarget | null
+ stopImmediatePropagation(): void
+ stopPropagation(): void
+ readonly target: EventTarget | null
+ readonly timeStamp: number
+ readonly type: string
+ }
export interface EventInit {
bubbles?: boolean
From 3794dd53e3cba9718e77e732a2389ef161617edc Mon Sep 17 00:00:00 2001
From: Khafra <42794878+KhafraDev@users.noreply.github.com>
Date: Mon, 7 Nov 2022 14:57:07 -0500
Subject: [PATCH 3/5] fix: try new approach
---
types/filereader.d.ts | 8 ++++++--
types/patch.d.ts | 12 ++++++------
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/types/filereader.d.ts b/types/filereader.d.ts
index 902a6bcf87c..0a89bb2887c 100644
--- a/types/filereader.d.ts
+++ b/types/filereader.d.ts
@@ -3,7 +3,9 @@
import { Blob } from 'buffer'
import { DOMException, Event, EventInit, EventTarget } from './patch'
-export declare class FileReader extends EventTarget {
+export declare class FileReader {
+ __proto__: EventTarget
+
constructor ()
readAsArrayBuffer (blob: Blob): void
@@ -41,7 +43,9 @@ export interface ProgressEventInit extends EventInit {
total?: number
}
-export declare class ProgressEvent extends Event {
+export declare class ProgressEvent {
+ __proto__: Event
+
constructor (type: string, eventInitDict?: ProgressEventInit)
readonly lengthComputable: boolean
diff --git a/types/patch.d.ts b/types/patch.d.ts
index abd04dae037..f3500b589a4 100644
--- a/types/patch.d.ts
+++ b/types/patch.d.ts
@@ -6,23 +6,23 @@ export type DOMException = typeof globalThis extends { DOMException: infer T }
? T
: any
-export type EventTarget = typeof globalThis extends { EventTarget: { prototype: infer T } }
+export type EventTarget = typeof globalThis extends { EventTarget: infer T }
? T
: {
addEventListener(
type: string,
- listener: EventListener | EventListenerObject,
- options?: AddEventListenerOptions | boolean,
+ listener: any,
+ options?: any,
): void
dispatchEvent(event: Event): boolean
removeEventListener(
type: string,
- listener: EventListener | EventListenerObject,
- options?: EventListenerOptions | boolean,
+ listener: any,
+ options?: any | boolean,
): void
}
-export type Event = typeof globalThis extends { Event: { prototype: infer T } }
+export type Event = typeof globalThis extends { Event: infer T }
? T
: {
readonly bubbles: boolean
From 9acf768cff12020146f6a5aca4b27897675a1bf1 Mon Sep 17 00:00:00 2001
From: Khafra <42794878+KhafraDev@users.noreply.github.com>
Date: Mon, 7 Nov 2022 16:59:16 -0500
Subject: [PATCH 4/5] fix: slightly more accurate types
---
types/filereader.d.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/types/filereader.d.ts b/types/filereader.d.ts
index 0a89bb2887c..5a1286aa7e2 100644
--- a/types/filereader.d.ts
+++ b/types/filereader.d.ts
@@ -4,7 +4,7 @@ import { Blob } from 'buffer'
import { DOMException, Event, EventInit, EventTarget } from './patch'
export declare class FileReader {
- __proto__: EventTarget
+ __proto__: EventTarget['prototype'] & FileReader
constructor ()
@@ -44,7 +44,7 @@ export interface ProgressEventInit extends EventInit {
}
export declare class ProgressEvent {
- __proto__: Event
+ __proto__: Event & ProgressEvent
constructor (type: string, eventInitDict?: ProgressEventInit)
From f39dd76dc676db0bc6a295ce14691b5022589bab Mon Sep 17 00:00:00 2001
From: Khafra <42794878+KhafraDev@users.noreply.github.com>
Date: Mon, 7 Nov 2022 17:00:14 -0500
Subject: [PATCH 5/5] fix: slightly more accurate types
---
types/filereader.d.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/types/filereader.d.ts b/types/filereader.d.ts
index 5a1286aa7e2..f05d231b2ff 100644
--- a/types/filereader.d.ts
+++ b/types/filereader.d.ts
@@ -4,7 +4,7 @@ import { Blob } from 'buffer'
import { DOMException, Event, EventInit, EventTarget } from './patch'
export declare class FileReader {
- __proto__: EventTarget['prototype'] & FileReader
+ __proto__: EventTarget & FileReader
constructor ()