Skip to content

Commit

Permalink
Fix dom depedendency and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
segevfiner committed Jul 22, 2022
1 parent 1cdd2c4 commit dce4bc2
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 12 deletions.
28 changes: 24 additions & 4 deletions types/node/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ interface AbortSignal {
* @since v17.3.0
*/
throwIfAborted(): void;
addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | NodeJS.AddEventListenerOptions): void;
addEventListener(type: string, listener: NodeJS.EventListenerOrEventListenerObject, options?: boolean | NodeJS.AddEventListenerOptions): void;
removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | NodeJS.EventListenerOptions): void;
removeEventListener(type: string, listener: NodeJS.EventListenerOrEventListenerObject, options?: boolean | NodeJS.EventListenerOptions): void;
}

declare var AbortController: {
Expand Down Expand Up @@ -310,4 +310,24 @@ declare namespace NodeJS {
interface ReadOnlyDict<T> {
readonly [key: string]: T | undefined;
}

interface EventListener {
(evt: Event): void;
}

interface EventListenerObject {
handleEvent(object: Event): void;
}

type EventListenerOrEventListenerObject = EventListener | EventListenerObject;

interface EventListenerOptions {
capture?: boolean;
}

interface AddEventListenerOptions extends EventListenerOptions {
once?: boolean;
passive?: boolean;
signal?: AbortSignal;
}
}
13 changes: 13 additions & 0 deletions types/node/test/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ declare var RANDOM_GLOBAL_VARIABLE: true;
const arrayBuffer = new ArrayBuffer(0);
structuredClone({ test: arrayBuffer }, { transfer: [arrayBuffer] }); // $ExpectType { test: ArrayBuffer; }
}

// AbortController & AbortSignal
{
const controller = new AbortController();
let bool: boolean;
bool = controller.signal.aborted;
const listener = (event: Event) => {};
controller.signal.addEventListener("abort", listener);
controller.signal.removeEventListener("abort", listener);
controller.signal.onabort = listener;
controller.signal.throwIfAborted();
controller.abort();
}
27 changes: 23 additions & 4 deletions types/node/v14/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ interface AbortSignal {
*/
readonly aborted: boolean;
onabort: ((this: AbortSignal, ev: Event) => any) | null;
addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | NodeJS.AddEventListenerOptions): void;
addEventListener(type: string, listener: NodeJS.EventListenerOrEventListenerObject, options?: boolean | NodeJS.AddEventListenerOptions): void;
removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | NodeJS.EventListenerOptions): void;
removeEventListener(type: string, listener: NodeJS.EventListenerOrEventListenerObject, options?: boolean | NodeJS.EventListenerOptions): void;
}

declare var AbortController: {
Expand Down Expand Up @@ -752,4 +752,23 @@ declare namespace NodeJS {
interface ReadOnlyDict<T> {
readonly [key: string]: T | undefined;
}

interface EventListener {
(evt: Event): void;
}

interface EventListenerObject {
handleEvent(object: Event): void;
}

type EventListenerOrEventListenerObject = EventListener | EventListenerObject;

interface EventListenerOptions {
capture?: boolean;
}

interface AddEventListenerOptions extends EventListenerOptions {
once?: boolean;
passive?: boolean;
}
}
12 changes: 12 additions & 0 deletions types/node/v14/test/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ declare var RANDOM_GLOBAL_VARIABLE: true;

const abortController = new global.AbortController();
abortController.signal; // $ExpectType AbortSignal

// AbortController & AbortSignal
{
const controller = new AbortController();
let bool: boolean;
bool = controller.signal.aborted;
const listener = (event: Event) => {};
controller.signal.addEventListener("abort", listener);
controller.signal.removeEventListener("abort", listener);
controller.signal.onabort = listener;
controller.abort();
}
27 changes: 23 additions & 4 deletions types/node/v16/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ interface AbortSignal {
* @since v16.14.0
*/
readonly reason: any;
addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
addEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | NodeJS.AddEventListenerOptions): void;
addEventListener(type: string, listener: NodeJS.EventListenerOrEventListenerObject, options?: boolean | NodeJS.AddEventListenerOptions): void;
removeEventListener<K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | NodeJS.EventListenerOptions): void;
removeEventListener(type: string, listener: NodeJS.EventListenerOrEventListenerObject, options?: boolean | NodeJS.EventListenerOptions): void;
}

declare var AbortController: {
Expand Down Expand Up @@ -295,4 +295,23 @@ declare namespace NodeJS {
interface ReadOnlyDict<T> {
readonly [key: string]: T | undefined;
}

interface EventListener {
(evt: Event): void;
}

interface EventListenerObject {
handleEvent(object: Event): void;
}

type EventListenerOrEventListenerObject = EventListener | EventListenerObject;

interface EventListenerOptions {
capture?: boolean;
}

interface AddEventListenerOptions extends EventListenerOptions {
once?: boolean;
passive?: boolean;
}
}
13 changes: 13 additions & 0 deletions types/node/v16/test/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ declare var RANDOM_GLOBAL_VARIABLE: true;
gc();
}
}

// AbortController & AbortSignal
{
const controller = new AbortController();
let bool: boolean;
bool = controller.signal.aborted;
controller.signal.reason;
const listener = (event: Event) => {};
controller.signal.addEventListener("abort", listener);
controller.signal.removeEventListener("abort", listener);
controller.signal.onabort = listener;
controller.abort();
}

0 comments on commit dce4bc2

Please sign in to comment.