Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions types/node/child_process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare module 'child_process' {
* 3. error
* 4. exit
* 5. message
* 6. spawn
*/

addListener(event: string, listener: (...args: any[]) => void): this;
Expand All @@ -49,41 +50,47 @@ declare module 'child_process' {
addListener(event: "error", listener: (err: Error) => void): this;
addListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
addListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
addListener(event: "spawn", listener: () => void): this;

emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close", code: number | null, signal: NodeJS.Signals | null): boolean;
emit(event: "disconnect"): boolean;
emit(event: "error", err: Error): boolean;
emit(event: "exit", code: number | null, signal: NodeJS.Signals | null): boolean;
emit(event: "message", message: Serializable, sendHandle: SendHandle): boolean;
emit(event: "spawn", listener: () => void): boolean;

on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
on(event: "disconnect", listener: () => void): this;
on(event: "error", listener: (err: Error) => void): this;
on(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
on(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
on(event: "spawn", listener: () => void): this;

once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
once(event: "disconnect", listener: () => void): this;
once(event: "error", listener: (err: Error) => void): this;
once(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
once(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
once(event: "spawn", listener: () => void): this;

prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
prependListener(event: "disconnect", listener: () => void): this;
prependListener(event: "error", listener: (err: Error) => void): this;
prependListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
prependListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
prependListener(event: "spawn", listener: () => void): this;

prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
prependOnceListener(event: "disconnect", listener: () => void): this;
prependOnceListener(event: "error", listener: (err: Error) => void): this;
prependOnceListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
prependOnceListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
prependOnceListener(event: "spawn", listener: () => void): this;
}

// return this object when stdio option is undefined or not specified
Expand Down
34 changes: 34 additions & 0 deletions types/node/diagnostic_channel.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @experimental
*/
declare module 'diagnostic_channel' {
/**
* Returns wether a named channel has subscribers or not.
*/
function hasSubscribers(name: string): boolean;

/**
* Gets or create a diagnostic channel by name.
*/
function channel(name: string): Channel;

type ChannelListener = (name: string, message: unknown) => void;

/**
* Simple diagnostic channel that allows
*/
class Channel {
readonly name: string;
readonly hashSubscribers: boolean;
private constructor(name: string);

/**
* Add a listener to the message channel.
*/
subscribe(listener: ChannelListener): void;
/**
* Removes a previously registered listener.
*/
unsubscribe(listener: ChannelListener): void;
}
}
4 changes: 4 additions & 0 deletions types/node/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ declare module 'events' {

/** @deprecated since v4.0.0 */
static listenerCount(emitter: NodeJS.EventEmitter, event: string | symbol): number;
/**
* Returns a list listener for a specific emitter event name.
*/
static getEventListener(emitter: DOMEventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];

/**
* This symbol shall be used to install a listener for only monitoring `'error'`
Expand Down
46 changes: 32 additions & 14 deletions types/node/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ declare module 'fs' {
prependOnceListener(event: "close", listener: () => void): this;
}

// TODO: Move this to a more central location
export interface Abortable {
signal?: AbortSignal;
}

export class ReadStream extends stream.Readable {
close(): void;
bytesRead: number;
Expand Down Expand Up @@ -552,13 +557,21 @@ declare module 'fs' {
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
}

export interface StatSyncFn<TDescriptor = PathLike> extends Function {
(path: TDescriptor, options?: undefined): Stats;
(path: TDescriptor, options?: StatOptions & { bigint?: false; throwIfNoEntry: false }): Stats | undefined;
(path: TDescriptor, options: StatOptions & { bigint: true; throwIfNoEntry: false }): BigIntStats | undefined;
(path: TDescriptor, options?: StatOptions & { bigint?: false }): Stats;
(path: TDescriptor, options: StatOptions & { bigint: true }): BigIntStats;
(path: TDescriptor, options: StatOptions & { bigint: boolean; throwIfNoEntry?: false }): Stats | BigIntStats;
(path: TDescriptor, options?: StatOptions): Stats | BigIntStats | undefined;
}

/**
* Synchronous stat(2) - Get file status.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
export function statSync(path: PathLike, options?: StatOptions & { bigint?: false }): Stats;
export function statSync(path: PathLike, options: StatOptions & { bigint: true }): BigIntStats;
export function statSync(path: PathLike, options?: StatOptions): Stats | BigIntStats;
export const statSync: StatSyncFn;

/**
* Asynchronous fstat(2) - Get file status.
Expand All @@ -584,9 +597,7 @@ declare module 'fs' {
* Synchronous fstat(2) - Get file status.
* @param fd A file descriptor.
*/
export function fstatSync(fd: number, options?: StatOptions & { bigint?: false }): Stats;
export function fstatSync(fd: number, options: StatOptions & { bigint: true }): BigIntStats;
export function fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats;
export const fstatSync: StatSyncFn<number>;

/**
* Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
Expand All @@ -612,10 +623,7 @@ declare module 'fs' {
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
export function lstatSync(path: PathLike, options?: StatOptions & { bigint?: false }): Stats;
export function lstatSync(path: PathLike, options: StatOptions & { bigint: true }): BigIntStats;
export function lstatSync(path: PathLike, options?: StatOptions): Stats | BigIntStats;

export const lstatSync: StatSyncFn;
/**
* Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
* @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
Expand Down Expand Up @@ -1557,7 +1565,11 @@ declare module 'fs' {
* @param options An object that may contain an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*/
export function readFile(path: PathLike | number, options: { encoding?: null; flag?: string; } | undefined | null, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
export function readFile(
path: PathLike | number,
options: { encoding?: null; flag?: string; } & Abortable | undefined | null,
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
): void;

/**
* Asynchronously reads the entire contents of a file.
Expand All @@ -1567,7 +1579,11 @@ declare module 'fs' {
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*/
export function readFile(path: PathLike | number, options: { encoding: BufferEncoding; flag?: string; } | string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
export function readFile(
path: PathLike | number,
options: { encoding: BufferEncoding; flag?: string; } & Abortable | string,
callback: (err: NodeJS.ErrnoException | null, data: string) => void,
): void;

/**
* Asynchronously reads the entire contents of a file.
Expand All @@ -1579,7 +1595,8 @@ declare module 'fs' {
*/
export function readFile(
path: PathLike | number,
options: BaseEncodingOptions & { flag?: string; } | string | undefined | null,
// TODO: unify the options across all readfile functions
options: BaseEncodingOptions & { flag?: string; } & Abortable | string | undefined | null,
callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
): void;

Expand Down Expand Up @@ -1651,7 +1668,7 @@ declare module 'fs' {
*/
export function readFileSync(path: PathLike | number, options?: BaseEncodingOptions & { flag?: string; } | BufferEncoding | null): string | Buffer;

export type WriteFileOptions = BaseEncodingOptions & { mode?: Mode; flag?: string; } | string | null;
export type WriteFileOptions = (BaseEncodingOptions & Abortable & { mode?: Mode; flag?: string; }) | string | null;

/**
* Asynchronously writes data to a file, replacing the file if it already exists.
Expand Down Expand Up @@ -2253,5 +2270,6 @@ declare module 'fs' {

export interface StatOptions {
bigint?: boolean;
throwIfNoEntry?: boolean;
}
}
11 changes: 6 additions & 5 deletions types/node/fs/promises.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare module 'fs/promises' {
BufferEncodingOption,
OpenMode,
Mode,
Abortable,
} from 'fs';

interface FileHandle {
Expand Down Expand Up @@ -143,7 +144,7 @@ declare module 'fs/promises' {
* If `mode` is a string, it is parsed as an octal integer.
* If `flag` is not supplied, the default of `'w'` is used.
*/
writeFile(data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } | BufferEncoding | null): Promise<void>;
writeFile(data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } & Abortable | BufferEncoding | null): Promise<void>;

/**
* See `fs.writev` promisified version.
Expand Down Expand Up @@ -510,7 +511,7 @@ declare module 'fs/promises' {
* If `mode` is a string, it is parsed as an octal integer.
* If `flag` is not supplied, the default of `'w'` is used.
*/
function writeFile(path: PathLike | FileHandle, data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } | BufferEncoding | null): Promise<void>;
function writeFile(path: PathLike | FileHandle, data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } & Abortable | BufferEncoding | null): Promise<void>;

/**
* Asynchronously append data to a file, creating the file if it does not exist.
Expand All @@ -533,7 +534,7 @@ declare module 'fs/promises' {
* @param options An object that may contain an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*/
function readFile(path: PathLike | FileHandle, options?: { encoding?: null, flag?: OpenMode } | null): Promise<Buffer>;
function readFile(path: PathLike | FileHandle, options?: { encoding?: null, flag?: OpenMode } & Abortable | null): Promise<Buffer>;

/**
* Asynchronously reads the entire contents of a file.
Expand All @@ -542,7 +543,7 @@ declare module 'fs/promises' {
* @param options An object that may contain an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*/
function readFile(path: PathLike | FileHandle, options: { encoding: BufferEncoding, flag?: OpenMode } | BufferEncoding): Promise<string>;
function readFile(path: PathLike | FileHandle, options: { encoding: BufferEncoding, flag?: OpenMode } & Abortable | BufferEncoding): Promise<string>;

/**
* Asynchronously reads the entire contents of a file.
Expand All @@ -551,7 +552,7 @@ declare module 'fs/promises' {
* @param options An object that may contain an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*/
function readFile(path: PathLike | FileHandle, options?: BaseEncodingOptions & { flag?: OpenMode } | BufferEncoding | null): Promise<string | Buffer>;
function readFile(path: PathLike | FileHandle, options?: BaseEncodingOptions & Abortable & { flag?: OpenMode } | BufferEncoding | null): Promise<string | Buffer>;

function opendir(path: string, options?: OpenDirOptions): Promise<Dir>;
}
1 change: 1 addition & 0 deletions types/node/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ declare module 'http' {
}

interface ClientRequestArgs {
abort?: AbortSignal;
protocol?: string | null;
host?: string | null;
hostname?: string | null;
Expand Down
17 changes: 11 additions & 6 deletions types/node/http2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,16 @@ declare module 'http2' {
origins?: string[];
}

export interface Http2Server extends net.Server {
interface HTTP2ServerCommon {
setTimeout(msec?: number, callback?: () => void): this;
/**
* Throws ERR_HTTP2_INVALID_SETTING_VALUE for invalid settings values.
* Throws ERR_INVALID_ARG_TYPE for invalid settings argument.
*/
updateSettings(settings: Settings): void;
}

export interface Http2Server extends net.Server, HTTP2ServerCommon {
addListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
addListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
Expand Down Expand Up @@ -514,11 +523,9 @@ declare module 'http2' {
prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
prependOnceListener(event: "timeout", listener: () => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;

setTimeout(msec?: number, callback?: () => void): this;
}

export interface Http2SecureServer extends tls.Server {
export interface Http2SecureServer extends tls.Server, HTTP2ServerCommon {
addListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
addListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
Expand Down Expand Up @@ -572,8 +579,6 @@ declare module 'http2' {
prependOnceListener(event: "timeout", listener: () => void): this;
prependOnceListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;

setTimeout(msec?: number, callback?: () => void): this;
}

export class Http2ServerRequest extends stream.Readable {
Expand Down
2 changes: 1 addition & 1 deletion types/node/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for non-npm package Node.js 15.0
// Type definitions for non-npm package Node.js 15.3
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
Expand Down
10 changes: 10 additions & 0 deletions types/node/path.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
declare module 'path/posix' {
import path = require('path');
export = path;
}

declare module 'path/win32' {
import path = require('path');
export = path;
}

declare module 'path' {
namespace path {
/**
Expand Down
11 changes: 7 additions & 4 deletions types/node/perf_hooks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ declare module 'perf_hooks' {
utilization: number;
}

/**
* @param util1 The result of a previous call to eventLoopUtilization()
* @param util2 The result of a previous call to eventLoopUtilization() prior to util1
*/
type EventLoopUtilityFunction = (util1?: EventLoopUtilization, util2?: EventLoopUtilization) => EventLoopUtilization;

interface Performance {
/**
* If name is not provided, removes all PerformanceMark objects from the Performance Timeline.
Expand Down Expand Up @@ -144,11 +150,8 @@ declare module 'perf_hooks' {
* eventLoopUtilization is similar to CPU utilization except that it is calculated using high precision wall-clock time.
* It represents the percentage of time the event loop has spent outside the event loop's event provider (e.g. epoll_wait).
* No other CPU idle time is taken into consideration.
*
* @param util1 The result of a previous call to eventLoopUtilization()
* @param util2 The result of a previous call to eventLoopUtilization() prior to util1
*/
eventLoopUtilization(util1?: EventLoopUtilization, util2?: EventLoopUtilization): EventLoopUtilization;
eventLoopUtilization: EventLoopUtilityFunction;
}

interface PerformanceObserverEntryList {
Expand Down
1 change: 1 addition & 0 deletions types/node/readline.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ declare module 'readline' {
*/
protected constructor(options: ReadLineOptions);

getPrompt(): string;
setPrompt(prompt: string): void;
prompt(preserveCursor?: boolean): void;
question(query: string, callback: (answer: string) => void): void;
Expand Down
12 changes: 12 additions & 0 deletions types/node/test/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,15 @@ b.fill('a').fill('b');
const target: TranscodeEncoding = 'ascii';
transcode(Buffer.from('€'), source, target); // $ExpectType Buffer
}

{
const a = Buffer.alloc(1000);
a.writeBigInt64BE(123n);
a.writeBigInt64LE(123n);
a.writeBigUInt64BE(123n);
a.writeBigUInt64LE(123n);
let b: bigint = a.readBigInt64BE(123);
b = a.readBigInt64LE(123);
b = a.readBigUInt64LE(123);
b = a.readBigUInt64BE(123);
}
Loading