Skip to content

Commit

Permalink
Fix filereader types (nodejs#1762)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and crysmags committed Feb 27, 2024
1 parent a759099 commit ebb6841
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -116,8 +116,7 @@
"compilerOptions": {
"esModuleInterop": true,
"lib": [
"esnext",
"DOM"
"esnext"
]
}
},
Expand Down
11 changes: 8 additions & 3 deletions types/filereader.d.ts
@@ -1,8 +1,11 @@
/// <reference types="node" />

import { Blob } from 'buffer'
import { DOMException, Event, EventInit, EventTarget } from './patch'

export declare class FileReader {
__proto__: EventTarget & FileReader

export declare class FileReader extends EventTarget {
constructor ()

readAsArrayBuffer (blob: Blob): void
Expand Down Expand Up @@ -40,10 +43,12 @@ export interface ProgressEventInit extends EventInit {
total?: number
}

export declare class ProgressEvent extends Event {
export declare class ProgressEvent {
__proto__: Event & ProgressEvent

constructor (type: string, eventInitDict?: ProgressEventInit)

readonly lengthComputable: boolean
readonly loaded: number
readonly total: number
}
}
51 changes: 51 additions & 0 deletions types/patch.d.ts
@@ -0,0 +1,51 @@
/// <reference types="node" />

// 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
: {
addEventListener(
type: string,
listener: any,
options?: any,
): void
dispatchEvent(event: Event): boolean
removeEventListener(
type: string,
listener: any,
options?: any | boolean,
): void
}

export type Event = typeof globalThis extends { Event: infer T }
? T
: {
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
cancelable?: boolean
composed?: boolean
}

0 comments on commit ebb6841

Please sign in to comment.