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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filereader types #1762

Merged
merged 5 commits into from Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}