Skip to content
Closed

Fix node #62729

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions types/node/buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ declare module 'buffer' {
import { Blob as NodeBlob } from 'buffer';
// This conditional type will be the existing global Blob in a browser, or
// the copy below in a Node environment.
type __Blob = typeof globalThis extends { onmessage: any, Blob: infer T }
? T : NodeBlob;
type __Blob = typeof globalThis extends { onmessage: any }
? {} : NodeBlob;
global {
// Buffer class
type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
Expand Down
16 changes: 8 additions & 8 deletions types/node/dom-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export {}; // Don't export anything!

// This conditional type will be the existing global Event in a browser, or
// the copy below in a Node environment.
type __Event = typeof globalThis extends { onmessage: any, Event: infer T }
? T
type __Event = typeof globalThis extends { onmessage: any }
? {}
: {
/** This is not used in Node.js and is provided purely for completeness. */
readonly bubbles: boolean;
Expand Down Expand Up @@ -48,8 +48,8 @@ type __Event = typeof globalThis extends { onmessage: any, Event: infer T }
};

// See comment above explaining conditional type
type __EventTarget = typeof globalThis extends { onmessage: any, EventTarget: infer T }
? T
type __EventTarget = typeof globalThis extends { onmessage: any }
? {}
: {
/**
* Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value.
Expand Down Expand Up @@ -108,8 +108,8 @@ declare global {
var Event: typeof globalThis extends { onmessage: any, Event: infer T }
? T
: {
prototype: __Event;
new (type: string, eventInitDict?: EventInit): __Event;
prototype: Event;
new (type: string, eventInitDict?: EventInit): Event;
};

/**
Expand All @@ -120,7 +120,7 @@ declare global {
var EventTarget: typeof globalThis extends { onmessage: any, EventTarget: infer T }
? T
: {
prototype: __EventTarget;
new (): __EventTarget;
prototype: EventTarget;
new (): EventTarget;
};
}
1 change: 1 addition & 0 deletions types/node/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './test/crypto';
import './test/dgram';
import './test/diagnostics_channel';
import './test/dns';
import './test/dom-events';
import './test/events';
import './test/fs';
import './test/globals';
Expand Down
2 changes: 2 additions & 0 deletions types/node/test/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ async () => {
encoding: 'base64',
});

typeof blob === 'object' && blob.type;

blob.size; // $ExpectType number
blob.type; // $ExpectType string

Expand Down
4 changes: 4 additions & 0 deletions types/node/test/dom-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'node';

(et: EventTarget) => typeof et === 'object' && et.addEventListener;
(ev: Event) => typeof ev === 'object' && ev.type;
4 changes: 2 additions & 2 deletions types/node/ts4.8/buffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ declare module 'buffer' {
import { Blob as NodeBlob } from 'buffer';
// This conditional type will be the existing global Blob in a browser, or
// the copy below in a Node environment.
type __Blob = typeof globalThis extends { onmessage: any, Blob: infer T }
? T : NodeBlob;
type __Blob = typeof globalThis extends { onmessage: any }
? {} : NodeBlob;

global {
// Buffer class
Expand Down
16 changes: 8 additions & 8 deletions types/node/ts4.8/dom-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export {}; // Don't export anything!

// This conditional type will be the existing global Event in a browser, or
// the copy below in a Node environment.
type __Event = typeof globalThis extends { onmessage: any, Event: infer T }
? T
type __Event = typeof globalThis extends { onmessage: any }
? {}
: {
/** This is not used in Node.js and is provided purely for completeness. */
readonly bubbles: boolean;
Expand Down Expand Up @@ -48,8 +48,8 @@ type __Event = typeof globalThis extends { onmessage: any, Event: infer T }
};

// See comment above explaining conditional type
type __EventTarget = typeof globalThis extends { onmessage: any, EventTarget: infer T }
? T
type __EventTarget = typeof globalThis extends { onmessage: any }
? {}
: {
/**
* Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value.
Expand Down Expand Up @@ -108,8 +108,8 @@ declare global {
var Event: typeof globalThis extends { onmessage: any, Event: infer T }
? T
: {
prototype: __Event;
new (type: string, eventInitDict?: EventInit): __Event;
prototype: Event;
new (type: string, eventInitDict?: EventInit): Event;
};

/**
Expand All @@ -120,7 +120,7 @@ declare global {
var EventTarget: typeof globalThis extends { onmessage: any, EventTarget: infer T }
? T
: {
prototype: __EventTarget;
new (): __EventTarget;
prototype: EventTarget;
new (): EventTarget;
};
}