chore(node): consolidate encoding and misc data types

This commit is contained in:
Simon Schick 2020-04-21 18:15:06 -07:00
parent 4b2129de54
commit daf04e0dcb
41 changed files with 478 additions and 245 deletions

View File

@ -19,7 +19,7 @@ let strOrBuf: string | Buffer;
let buffer: Buffer;
declare const modeNum: number;
declare const modeStr: string;
declare const encoding: string;
declare const encoding: BufferEncoding;
declare const symlinkType: "file" | "dir" | "junction";
declare const flags: string;
declare const srcpath: string;
@ -195,14 +195,14 @@ bool = fs.existsSync(path);
readStream = fs.createReadStream(path);
readStream = fs.createReadStream(path, {
flags: str,
encoding: str,
encoding: str as BufferEncoding,
fd: num,
mode: num
});
writeStream = fs.createWriteStream(path);
writeStream = fs.createWriteStream(path, {
flags: str,
encoding: str
encoding: str as BufferEncoding
});
function isDirectoryCallback(err: Error, isDirectory: boolean) {}

View File

@ -280,12 +280,12 @@ export interface ReadOptions {
throws?: boolean;
fs?: object;
reviver?: any;
encoding?: string;
encoding?: BufferEncoding;
flag?: string;
}
export interface WriteFileOptions {
encoding?: string;
encoding?: BufferEncoding;
flag?: string;
mode?: number;
}

View File

@ -22,7 +22,7 @@ export class Parser extends Stream {
parse(buf: Buffer | string, isFinal?: boolean): boolean;
setEncoding(encoding: string): void;
setEncoding(encoding: BufferEncoding): void;
setUnknownEncoding(map: number[], convert?: string): void;
@ -40,7 +40,7 @@ export class Parser extends Stream {
end(cb?: () => void): void;
end(chunk: any, cb?: () => void): void;
end(chunk: any, encoding: string, cb?: () => void): void;
end(chunk: any, encoding: BufferEncoding, cb?: () => void): void;
reset(): void;

View File

@ -117,7 +117,7 @@ const notifier4 = new notifier.Growl({
notifier4.notify({
title: 'Foo',
message: 'Hello World',
icon: fs.readFileSync(__dirname + '/coulson.jpg', 'r'),
icon: fs.readFileSync(__dirname + '/coulson.jpg', 'utf8'),
wait: false, // if wait for user interaction
// and other growl options like sticky etc.

View File

@ -1,4 +1,5 @@
declare module "child_process" {
import { BaseEncodingOptions } from 'fs';
import * as events from "events";
import * as net from "net";
import { Writable, Readable, Stream, Pipe } from "stream";
@ -268,7 +269,7 @@ declare module "child_process" {
}
interface ExecOptionsWithBufferEncoding extends ExecOptions {
encoding: string | null; // specify `null`.
encoding: BufferEncoding | null; // specify `null`.
}
interface ExecException extends Error {
@ -289,7 +290,11 @@ declare module "child_process" {
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
function exec(command: string, options: { encoding: string } & ExecOptions, callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
function exec(
command: string,
options: { encoding: BufferEncoding } & ExecOptions,
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
): ChildProcess;
// `options` without an `encoding` means stdout/stderr are definitely `string`.
function exec(command: string, options: ExecOptions, callback?: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
@ -297,7 +302,7 @@ declare module "child_process" {
// fallback if nothing else matches. Worst case is always `string | Buffer`.
function exec(
command: string,
options: ({ encoding?: string | null } & ExecOptions) | undefined | null,
options: (BaseEncodingOptions & ExecOptions) | undefined | null,
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
): ChildProcess;
@ -311,7 +316,7 @@ declare module "child_process" {
function __promisify__(command: string, options: { encoding: "buffer" | null } & ExecOptions): PromiseWithChild<{ stdout: Buffer, stderr: Buffer }>;
function __promisify__(command: string, options: { encoding: BufferEncoding } & ExecOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
function __promisify__(command: string, options: ExecOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
function __promisify__(command: string, options?: ({ encoding?: string | null } & ExecOptions) | null): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
function __promisify__(command: string, options?: (BaseEncodingOptions & ExecOptions) | null): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
}
interface ExecFileOptions extends CommonOptions {
@ -327,13 +332,13 @@ declare module "child_process" {
encoding: 'buffer' | null;
}
interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {
encoding: string;
encoding: BufferEncoding;
}
function execFile(file: string): ChildProcess;
function execFile(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
function execFile(file: string, options: (BaseEncodingOptions & ExecFileOptions) | undefined | null): ChildProcess;
function execFile(file: string, args?: ReadonlyArray<string> | null): ChildProcess;
function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
function execFile(file: string, args: ReadonlyArray<string> | undefined | null, options: (BaseEncodingOptions & ExecFileOptions) | undefined | null): ChildProcess;
// no `options` definitely means stdout/stderr are `string`.
function execFile(file: string, callback: (error: ExecException | null, stdout: string, stderr: string) => void): ChildProcess;
@ -383,13 +388,13 @@ declare module "child_process" {
// fallback if nothing else matches. Worst case is always `string | Buffer`.
function execFile(
file: string,
options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
options: (BaseEncodingOptions & ExecFileOptions) | undefined | null,
callback: ((error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null,
): ChildProcess;
function execFile(
file: string,
args: ReadonlyArray<string> | undefined | null,
options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
options: (BaseEncodingOptions & ExecFileOptions) | undefined | null,
callback: ((error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null,
): ChildProcess;
@ -405,11 +410,11 @@ declare module "child_process" {
function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptionsWithOtherEncoding): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
function __promisify__(file: string, options: ExecFileOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptions): PromiseWithChild<{ stdout: string, stderr: string }>;
function __promisify__(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
function __promisify__(file: string, options: (BaseEncodingOptions & ExecFileOptions) | undefined | null): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
function __promisify__(
file: string,
args: string[] | undefined | null,
options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null,
options: (BaseEncodingOptions & ExecFileOptions) | undefined | null,
): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
}
@ -427,13 +432,13 @@ declare module "child_process" {
input?: string | NodeJS.ArrayBufferView;
killSignal?: NodeJS.Signals | number;
maxBuffer?: number;
encoding?: string;
encoding?: BufferEncoding;
}
interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
encoding: BufferEncoding;
}
interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
encoding: string; // specify `null`.
encoding: BufferEncoding; // specify `null`.
}
interface SpawnSyncReturns<T> {
pid: number;
@ -458,13 +463,13 @@ declare module "child_process" {
shell?: string;
killSignal?: NodeJS.Signals | number;
maxBuffer?: number;
encoding?: string;
encoding?: BufferEncoding;
}
interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
encoding: BufferEncoding;
}
interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
encoding: string; // specify `null`.
encoding: BufferEncoding; // specify `null`.
}
function execSync(command: string): Buffer;
function execSync(command: string, options?: ExecSyncOptionsWithStringEncoding): string;
@ -476,14 +481,14 @@ declare module "child_process" {
stdio?: StdioOptions;
killSignal?: NodeJS.Signals | number;
maxBuffer?: number;
encoding?: string;
encoding?: BufferEncoding;
shell?: boolean | string;
}
interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
encoding: BufferEncoding;
}
interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
encoding: string; // specify `null`.
encoding: BufferEncoding; // specify `null`.
}
function execFileSync(command: string): Buffer;
function execFileSync(command: string, options?: ExecFileSyncOptionsWithStringEncoding): string;

View File

@ -208,7 +208,7 @@ declare module "crypto" {
update(data: NodeJS.ArrayBufferView, input_encoding: undefined, output_encoding: HexBase64BinaryEncoding): string;
update(data: string, input_encoding: Utf8AsciiBinaryEncoding | undefined, output_encoding: HexBase64BinaryEncoding): string;
final(): Buffer;
final(output_encoding: string): string;
final(output_encoding: BufferEncoding): string;
setAutoPadding(auto_padding?: boolean): this;
// getAuthTag(): Buffer;
// setAAD(buffer: Buffer): this; // docs only say buffer
@ -249,7 +249,7 @@ declare module "crypto" {
update(data: NodeJS.ArrayBufferView, input_encoding: HexBase64BinaryEncoding | undefined, output_encoding: Utf8AsciiBinaryEncoding): string;
update(data: string, input_encoding: HexBase64BinaryEncoding | undefined, output_encoding: Utf8AsciiBinaryEncoding): string;
final(): Buffer;
final(output_encoding: string): string;
final(output_encoding: BufferEncoding): string;
setAutoPadding(auto_padding?: boolean): this;
// setAuthTag(tag: NodeJS.ArrayBufferView): this;
// setAAD(buffer: NodeJS.ArrayBufferView): this;
@ -337,9 +337,9 @@ declare module "crypto" {
getPrivateKey(): Buffer;
getPrivateKey(encoding: HexBase64Latin1Encoding): string;
setPublicKey(public_key: NodeJS.ArrayBufferView): void;
setPublicKey(public_key: string, encoding: string): void;
setPublicKey(public_key: string, encoding: BufferEncoding): void;
setPrivateKey(private_key: NodeJS.ArrayBufferView): void;
setPrivateKey(private_key: string, encoding: string): void;
setPrivateKey(private_key: string, encoding: BufferEncoding): void;
verifyError: number;
}
function getDiffieHellman(group_name: string): DiffieHellman;
@ -429,7 +429,7 @@ declare module "crypto" {
function createECDH(curve_name: string): ECDH;
function timingSafeEqual(a: NodeJS.ArrayBufferView, b: NodeJS.ArrayBufferView): boolean;
/** @deprecated since v10.0.0 */
const DEFAULT_ENCODING: string;
const DEFAULT_ENCODING: BufferEncoding;
type KeyType = 'rsa' | 'dsa' | 'ec';
type KeyFormat = 'pem' | 'der';

155
types/node/fs.d.ts vendored
View File

@ -2,8 +2,9 @@ declare module "fs" {
import * as stream from "stream";
import * as events from "events";
import { URL } from "url";
export * as promises from 'fs/promises';
import * as promises from 'fs/promises';
export { promises };
/**
* Valid types for path values in "fs".
*/
@ -11,6 +12,16 @@ declare module "fs" {
export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
export type BufferEncodingOption = 'buffer' | { encoding: 'buffer' };
export interface BaseEncodingOptions {
encoding?: BufferEncoding | null;
}
export type OpenMode = number | string;
export type Mode = number | string;
export interface StatsBase<T> {
isFile(): boolean;
isDirectory(): boolean;
@ -421,7 +432,7 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
export function chmod(path: PathLike, mode: string | number, callback: NoParamCallback): void;
export function chmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
export namespace chmod {
@ -430,7 +441,7 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
function __promisify__(path: PathLike, mode: string | number): Promise<void>;
function __promisify__(path: PathLike, mode: Mode): Promise<void>;
}
/**
@ -438,14 +449,14 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
export function chmodSync(path: PathLike, mode: string | number): void;
export function chmodSync(path: PathLike, mode: Mode): void;
/**
* Asynchronous fchmod(2) - Change permissions of a file.
* @param fd A file descriptor.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
export function fchmod(fd: number, mode: string | number, callback: NoParamCallback): void;
export function fchmod(fd: number, mode: Mode, callback: NoParamCallback): void;
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
export namespace fchmod {
@ -454,7 +465,7 @@ declare module "fs" {
* @param fd A file descriptor.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
function __promisify__(fd: number, mode: string | number): Promise<void>;
function __promisify__(fd: number, mode: Mode): Promise<void>;
}
/**
@ -462,14 +473,14 @@ declare module "fs" {
* @param fd A file descriptor.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
export function fchmodSync(fd: number, mode: string | number): void;
export function fchmodSync(fd: number, mode: Mode): void;
/**
* Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
export function lchmod(path: PathLike, mode: string | number, callback: NoParamCallback): void;
export function lchmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
export namespace lchmod {
@ -478,7 +489,7 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
function __promisify__(path: PathLike, mode: string | number): Promise<void>;
function __promisify__(path: PathLike, mode: Mode): Promise<void>;
}
/**
@ -486,7 +497,7 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
export function lchmodSync(path: PathLike, mode: string | number): void;
export function lchmodSync(path: PathLike, mode: Mode): void;
/**
* Asynchronous stat(2) - Get file status.
@ -621,7 +632,7 @@ declare module "fs" {
*/
export function readlink(
path: PathLike,
options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null,
options: BaseEncodingOptions | BufferEncoding | undefined | null,
callback: (err: NodeJS.ErrnoException | null, linkString: string) => void
): void;
@ -630,14 +641,14 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
export function readlink(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function readlink(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void): void;
export function readlink(path: PathLike, options: BaseEncodingOptions | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void): void;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
@ -652,21 +663,21 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
function __promisify__(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
function __promisify__(path: PathLike, options?: BaseEncodingOptions | string | null): Promise<string | Buffer>;
}
/**
@ -674,21 +685,21 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function readlinkSync(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
export function readlinkSync(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): string;
/**
* Synchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function readlinkSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer;
/**
* Synchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function readlinkSync(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
export function readlinkSync(path: PathLike, options?: BaseEncodingOptions | string | null): string | Buffer;
/**
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
@ -697,7 +708,7 @@ declare module "fs" {
*/
export function realpath(
path: PathLike,
options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null,
options: BaseEncodingOptions | BufferEncoding | undefined | null,
callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void
): void;
@ -706,14 +717,14 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
export function realpath(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
/**
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function realpath(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
export function realpath(path: PathLike, options: BaseEncodingOptions | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
/**
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
@ -728,29 +739,29 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
function __promisify__(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
/**
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
/**
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
function __promisify__(path: PathLike, options?: BaseEncodingOptions | string | null): Promise<string | Buffer>;
function native(
path: PathLike,
options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null,
options: BaseEncodingOptions | BufferEncoding | undefined | null,
callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void
): void;
function native(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
function native(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
function native(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
function native(path: PathLike, options: BaseEncodingOptions | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
}
@ -759,26 +770,26 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function realpathSync(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
export function realpathSync(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): string;
/**
* Synchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function realpathSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
/**
* Synchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function realpathSync(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
export function realpathSync(path: PathLike, options?: BaseEncodingOptions | string | null): string | Buffer;
export namespace realpathSync {
function native(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
function native(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
function native(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
function native(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): string;
function native(path: PathLike, options: BufferEncodingOption): Buffer;
function native(path: PathLike, options?: BaseEncodingOptions | string | null): string | Buffer;
}
/**
@ -864,7 +875,7 @@ declare module "fs" {
* A file mode. If a string is passed, it is parsed as an octal integer. If not specified
* @default 0o777
*/
mode?: number | string;
mode?: Mode;
}
/**
@ -881,7 +892,7 @@ declare module "fs" {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
export function mkdir(path: PathLike, options: number | string | (MakeDirectoryOptions & { recursive?: false; }) | null | undefined, callback: NoParamCallback): void;
export function mkdir(path: PathLike, options: Mode | (MakeDirectoryOptions & { recursive?: false; }) | null | undefined, callback: NoParamCallback): void;
/**
* Asynchronous mkdir(2) - create a directory.
@ -889,7 +900,7 @@ declare module "fs" {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
export function mkdir(path: PathLike, options: number | string | MakeDirectoryOptions | null | undefined, callback: (err: NodeJS.ErrnoException | null, path: string | undefined) => void): void;
export function mkdir(path: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: (err: NodeJS.ErrnoException | null, path: string | undefined) => void): void;
/**
* Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
@ -913,7 +924,7 @@ declare module "fs" {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
function __promisify__(path: PathLike, options?: number | string | (MakeDirectoryOptions & { recursive?: false; }) | null): Promise<void>;
function __promisify__(path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false; }) | null): Promise<void>;
/**
* Asynchronous mkdir(2) - create a directory.
@ -921,7 +932,7 @@ declare module "fs" {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
function __promisify__(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<string | undefined>;
function __promisify__(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
}
/**
@ -938,7 +949,7 @@ declare module "fs" {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
export function mkdirSync(path: PathLike, options?: number | string | (MakeDirectoryOptions & { recursive?: false; }) | null): void;
export function mkdirSync(path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false; }) | null): void;
/**
* Synchronous mkdir(2) - create a directory.
@ -946,14 +957,14 @@ declare module "fs" {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
export function mkdirSync(path: PathLike, options?: number | string | MakeDirectoryOptions | null): string | undefined;
export function mkdirSync(path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
/**
* Asynchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function mkdtemp(prefix: string, options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
export function mkdtemp(prefix: string, options: BaseEncodingOptions | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
/**
* Asynchronously creates a unique temporary directory.
@ -967,7 +978,7 @@ declare module "fs" {
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function mkdtemp(prefix: string, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
export function mkdtemp(prefix: string, options: BaseEncodingOptions | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
/**
* Asynchronously creates a unique temporary directory.
@ -982,21 +993,21 @@ declare module "fs" {
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
function __promisify__(prefix: string, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
/**
* Asynchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
function __promisify__(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
/**
* Asynchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(prefix: string, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
function __promisify__(prefix: string, options?: BaseEncodingOptions | string | null): Promise<string | Buffer>;
}
/**
@ -1004,21 +1015,21 @@ declare module "fs" {
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function mkdtempSync(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
export function mkdtempSync(prefix: string, options?: BaseEncodingOptions | BufferEncoding | null): string;
/**
* Synchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function mkdtempSync(prefix: string, options: { encoding: "buffer" } | "buffer"): Buffer;
export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
/**
* Synchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function mkdtempSync(prefix: string, options?: { encoding?: string | null } | string | null): string | Buffer;
export function mkdtempSync(prefix: string, options?: BaseEncodingOptions | string | null): string | Buffer;
/**
* Asynchronous readdir(3) - read a directory.
@ -1045,7 +1056,7 @@ declare module "fs" {
*/
export function readdir(
path: PathLike,
options: { encoding?: string | null; withFileTypes?: false } | string | undefined | null,
options: BaseEncodingOptions & { withFileTypes?: false } | BufferEncoding | undefined | null,
callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void,
): void;
@ -1060,7 +1071,7 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
*/
export function readdir(path: PathLike, options: { encoding?: string | null; withFileTypes: true }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void;
export function readdir(path: PathLike, options: BaseEncodingOptions & { withFileTypes: true }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void;
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
export namespace readdir {
@ -1083,14 +1094,14 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function __promisify__(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): Promise<string[] | Buffer[]>;
function __promisify__(path: PathLike, options?: BaseEncodingOptions & { withFileTypes?: false } | BufferEncoding | null): Promise<string[] | Buffer[]>;
/**
* Asynchronous readdir(3) - read a directory.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent
*/
function __promisify__(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Promise<Dirent[]>;
function __promisify__(path: PathLike, options: BaseEncodingOptions & { withFileTypes: true }): Promise<Dirent[]>;
}
/**
@ -1112,14 +1123,14 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
export function readdirSync(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): string[] | Buffer[];
export function readdirSync(path: PathLike, options?: BaseEncodingOptions & { withFileTypes?: false } | BufferEncoding | null): string[] | Buffer[];
/**
* Synchronous readdir(3) - read a directory.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
*/
export function readdirSync(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Dirent[];
export function readdirSync(path: PathLike, options: BaseEncodingOptions & { withFileTypes: true }): Dirent[];
/**
* Asynchronous close(2) - close a file descriptor.
@ -1147,13 +1158,13 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
*/
export function open(path: PathLike, flags: string | number, mode: string | number | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
export function open(path: PathLike, flags: OpenMode, mode: Mode | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
/**
* Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
export function open(path: PathLike, flags: string | number, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
export function open(path: PathLike, flags: OpenMode, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
export namespace open {
@ -1162,7 +1173,7 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
*/
function __promisify__(path: PathLike, flags: string | number, mode?: string | number | null): Promise<number>;
function __promisify__(path: PathLike, flags: OpenMode, mode?: Mode | null): Promise<number>;
}
/**
@ -1170,7 +1181,7 @@ declare module "fs" {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
*/
export function openSync(path: PathLike, flags: string | number, mode?: string | number | null): number;
export function openSync(path: PathLike, flags: OpenMode, mode?: Mode | null): number;
/**
* Asynchronously change file timestamps of the file referenced by the supplied path.
@ -1306,7 +1317,7 @@ declare module "fs" {
fd: number,
string: string,
position: number | undefined | null,
encoding: string | undefined | null,
encoding: BufferEncoding | undefined | null,
callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
): void;
@ -1349,7 +1360,7 @@ declare module "fs" {
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
* @param encoding The expected string encoding.
*/
function __promisify__(fd: number, string: string, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
function __promisify__(fd: number, string: string, position?: number | null, encoding?: BufferEncoding | null): Promise<{ bytesWritten: number, buffer: string }>;
}
/**
@ -1368,7 +1379,7 @@ declare module "fs" {
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
* @param encoding The expected string encoding.
*/
export function writeSync(fd: number, string: string, position?: number | null, encoding?: string | null): number;
export function writeSync(fd: number, string: string, position?: number | null, encoding?: BufferEncoding | null): number;
/**
* Asynchronously reads data from the file referenced by the supplied file descriptor.
@ -1453,7 +1464,7 @@ 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: string; flag?: string; } | string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
export function readFile(path: PathLike | number, options: { encoding: BufferEncoding; flag?: string; } | string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
/**
* Asynchronously reads the entire contents of a file.
@ -1465,7 +1476,7 @@ declare module "fs" {
*/
export function readFile(
path: PathLike | number,
options: { encoding?: string | null; flag?: string; } | string | undefined | null,
options: BaseEncodingOptions & { flag?: string; } | string | undefined | null,
callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
): void;
@ -1495,7 +1506,7 @@ 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'`.
*/
function __promisify__(path: PathLike | number, options: { encoding: string; flag?: string; } | string): Promise<string>;
function __promisify__(path: PathLike | number, options: { encoding: BufferEncoding; flag?: string; } | string): Promise<string>;
/**
* Asynchronously reads the entire contents of a file.
@ -1505,7 +1516,7 @@ 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'`.
*/
function __promisify__(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): Promise<string | Buffer>;
function __promisify__(path: PathLike | number, options?: BaseEncodingOptions & { flag?: string; } | string | null): Promise<string | Buffer>;
}
/**
@ -1525,7 +1536,7 @@ 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 readFileSync(path: PathLike | number, options: { encoding: string; flag?: string; } | string): string;
export function readFileSync(path: PathLike | number, options: { encoding: BufferEncoding; flag?: string; } | BufferEncoding): string;
/**
* Synchronously reads the entire contents of a file.
@ -1535,9 +1546,9 @@ 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 readFileSync(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): string | Buffer;
export function readFileSync(path: PathLike | number, options?: BaseEncodingOptions & { flag?: string; } | BufferEncoding | null): string | Buffer;
export type WriteFileOptions = { encoding?: string | null; mode?: number | string; flag?: string; } | string | null;
export type WriteFileOptions = BaseEncodingOptions & { mode?: Mode; flag?: string; } | string | null;
/**
* Asynchronously writes data to a file, replacing the file if it already exists.
@ -1703,7 +1714,7 @@ declare module "fs" {
*/
export function watch(
filename: PathLike,
options: { encoding?: string | null, persistent?: boolean, recursive?: boolean } | string | null,
options: { encoding?: BufferEncoding | null, persistent?: boolean, recursive?: boolean } | string | null,
listener?: (event: string, filename: string | Buffer) => void,
): FSWatcher;
@ -1939,7 +1950,7 @@ declare module "fs" {
*/
export function createReadStream(path: PathLike, options?: string | {
flags?: string;
encoding?: string;
encoding?: BufferEncoding;
fd?: number;
mode?: number;
autoClose?: boolean;
@ -1959,7 +1970,7 @@ declare module "fs" {
*/
export function createWriteStream(path: PathLike, options?: string | {
flags?: string;
encoding?: string;
encoding?: BufferEncoding;
fd?: number;
mode?: number;
autoClose?: boolean;

View File

@ -1,4 +1,3 @@
declare module 'fs/promises' {
import {
Stats,
@ -10,6 +9,10 @@ declare module 'fs/promises' {
Dirent,
OpenDirOptions,
Dir,
BaseEncodingOptions,
BufferEncodingOption,
OpenMode,
Mode,
} from 'fs';
interface FileHandle {
@ -28,7 +31,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 `'a'` is used.
*/
appendFile(data: string | Uint8Array, options?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
appendFile(data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } | BufferEncoding | null): Promise<void>;
/**
* Asynchronous fchown(2) - Change ownership of a file.
@ -39,7 +42,7 @@ declare module 'fs/promises' {
* Asynchronous fchmod(2) - Change permissions of a file.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
chmod(mode: string | number): Promise<void>;
chmod(mode: Mode): Promise<void>;
/**
* Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
@ -67,7 +70,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'`.
*/
readFile(options?: { encoding?: null, flag?: string | number } | null): Promise<Buffer>;
readFile(options?: { encoding?: null, flag?: OpenMode } | null): Promise<Buffer>;
/**
* Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
@ -75,7 +78,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'`.
*/
readFile(options: { encoding: BufferEncoding, flag?: string | number } | BufferEncoding): Promise<string>;
readFile(options: { encoding: BufferEncoding, flag?: OpenMode } | BufferEncoding): Promise<string>;
/**
* Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
@ -83,7 +86,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'`.
*/
readFile(options?: { encoding?: string | null, flag?: string | number } | string | null): Promise<string | Buffer>;
readFile(options?: BaseEncodingOptions & { flag?: OpenMode } | BufferEncoding | null): Promise<string | Buffer>;
/**
* Asynchronous fstat(2) - Get file status.
@ -122,7 +125,7 @@ declare module 'fs/promises' {
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
* @param encoding The expected string encoding.
*/
write(data: string | Uint8Array, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
write(data: string | Uint8Array, position?: number | null, encoding?: BufferEncoding | null): Promise<{ bytesWritten: number, buffer: string }>;
/**
* Asynchronously writes data to a file, replacing the file if it already exists. The underlying file will _not_ be closed automatically.
@ -135,7 +138,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?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
writeFile(data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } | BufferEncoding | null): Promise<void>;
/**
* See `fs.writev` promisified version.
@ -179,7 +182,7 @@ declare module 'fs/promises' {
* @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not
* supplied, defaults to `0o666`.
*/
function open(path: PathLike, flags: string | number, mode?: string | number): Promise<FileHandle>;
function open(path: PathLike, flags: string | number, mode?: Mode): Promise<FileHandle>;
/**
* Asynchronously reads data from the file referenced by the supplied `FileHandle`.
@ -223,7 +226,7 @@ declare module 'fs/promises' {
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
* @param encoding The expected string encoding.
*/
function write(handle: FileHandle, string: string, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
function write(handle: FileHandle, string: string, position?: number | null, encoding?: BufferEncoding | null): Promise<{ bytesWritten: number, buffer: string }>;
/**
* Asynchronous rename(2) - Change the name or location of a file or directory.
@ -280,7 +283,7 @@ declare module 'fs/promises' {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
function mkdir(path: PathLike, options?: number | string | (MakeDirectoryOptions & { recursive?: false; }) | null): Promise<void>;
function mkdir(path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false; }) | null): Promise<void>;
/**
* Asynchronous mkdir(2) - create a directory.
@ -288,14 +291,14 @@ declare module 'fs/promises' {
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
*/
function mkdir(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<string | undefined>;
function mkdir(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
/**
* Asynchronous readdir(3) - read a directory.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function readdir(path: PathLike, options?: { encoding?: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): Promise<string[]>;
function readdir(path: PathLike, options?: BaseEncodingOptions & { withFileTypes?: false } | BufferEncoding | null): Promise<string[]>;
/**
* Asynchronous readdir(3) - read a directory.
@ -309,35 +312,35 @@ declare module 'fs/promises' {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function readdir(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): Promise<string[] | Buffer[]>;
function readdir(path: PathLike, options?: BaseEncodingOptions & { withFileTypes?: false } | BufferEncoding | null): Promise<string[] | Buffer[]>;
/**
* Asynchronous readdir(3) - read a directory.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
*/
function readdir(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Promise<Dirent[]>;
function readdir(path: PathLike, options: BaseEncodingOptions & { withFileTypes: true }): Promise<Dirent[]>;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function readlink(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
function readlink(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
function readlink(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function readlink(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
function readlink(path: PathLike, options?: BaseEncodingOptions | string | null): Promise<string | Buffer>;
/**
* Asynchronous symlink(2) - Create a new symbolic link to an existing file.
@ -384,21 +387,21 @@ declare module 'fs/promises' {
* @param handle A `FileHandle`.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
function fchmod(handle: FileHandle, mode: string | number): Promise<void>;
function fchmod(handle: FileHandle, mode: Mode): Promise<void>;
/**
* Asynchronous chmod(2) - Change permissions of a file.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
function chmod(path: PathLike, mode: string | number): Promise<void>;
function chmod(path: PathLike, mode: Mode): Promise<void>;
/**
* Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param mode A file mode. If a string is passed, it is parsed as an octal integer.
*/
function lchmod(path: PathLike, mode: string | number): Promise<void>;
function lchmod(path: PathLike, mode: Mode): Promise<void>;
/**
* Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
@ -439,42 +442,42 @@ declare module 'fs/promises' {
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function realpath(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
function realpath(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
/**
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
function realpath(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
/**
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function realpath(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
function realpath(path: PathLike, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
/**
* Asynchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function mkdtemp(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
function mkdtemp(prefix: string, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string>;
/**
* Asynchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function mkdtemp(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
function mkdtemp(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
/**
* Asynchronously creates a unique temporary directory.
* Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
function mkdtemp(prefix: string, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
function mkdtemp(prefix: string, options?: BaseEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
/**
* Asynchronously writes data to a file, replacing the file if it already exists.
@ -489,7 +492,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?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
function writeFile(path: PathLike | FileHandle, data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } | BufferEncoding | null): Promise<void>;
/**
* Asynchronously append data to a file, creating the file if it does not exist.
@ -503,7 +506,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 `'a'` is used.
*/
function appendFile(path: PathLike | FileHandle, data: string | Uint8Array, options?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
function appendFile(path: PathLike | FileHandle, data: string | Uint8Array, options?: BaseEncodingOptions & { mode?: Mode, flag?: OpenMode } | BufferEncoding | null): Promise<void>;
/**
* Asynchronously reads the entire contents of a file.
@ -512,7 +515,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?: string | number } | null): Promise<Buffer>;
function readFile(path: PathLike | FileHandle, options?: { encoding?: null, flag?: OpenMode } | null): Promise<Buffer>;
/**
* Asynchronously reads the entire contents of a file.
@ -521,7 +524,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?: string | number } | BufferEncoding): Promise<string>;
function readFile(path: PathLike | FileHandle, options: { encoding: BufferEncoding, flag?: OpenMode } | BufferEncoding): Promise<string>;
/**
* Asynchronously reads the entire contents of a file.
@ -530,7 +533,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?: string | null, flag?: string | number } | string | null): Promise<string | Buffer>;
function readFile(path: PathLike | FileHandle, options?: BaseEncodingOptions & { flag?: OpenMode } | BufferEncoding | null): Promise<string | Buffer>;
function opendir(path: string, options?: OpenDirOptions): Promise<Dir>;
}

View File

@ -327,7 +327,7 @@ declare class Buffer extends Uint8Array {
write(string: string, encoding?: BufferEncoding): number;
write(string: string, offset: number, encoding?: BufferEncoding): number;
write(string: string, offset: number, length: number, encoding?: BufferEncoding): number;
toString(encoding?: string, start?: number, end?: number): string;
toString(encoding?: BufferEncoding, start?: number, end?: number): string;
toJSON(): { type: 'Buffer'; data: number[] };
equals(otherBuffer: Uint8Array): boolean;
compare(
@ -572,7 +572,7 @@ declare namespace NodeJS {
interface ReadableStream extends EventEmitter {
readable: boolean;
read(size?: number): string | Buffer;
setEncoding(encoding: string): this;
setEncoding(encoding: BufferEncoding): this;
pause(): this;
resume(): this;
isPaused(): boolean;
@ -586,10 +586,10 @@ declare namespace NodeJS {
interface WritableStream extends EventEmitter {
writable: boolean;
write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
write(str: string, encoding?: string, cb?: (err?: Error | null) => void): boolean;
write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
end(cb?: () => void): void;
end(data: string | Uint8Array, cb?: () => void): void;
end(str: string, encoding?: string, cb?: () => void): void;
end(str: string, encoding?: BufferEncoding, cb?: () => void): void;
}
interface ReadWriteStream extends ReadableStream, WritableStream { }

View File

@ -652,7 +652,7 @@ declare module "http2" {
addTrailers(trailers: OutgoingHttpHeaders): void;
end(callback?: () => void): void;
end(data: string | Uint8Array, callback?: () => void): void;
end(data: string | Uint8Array, encoding: string, callback?: () => void): void;
end(data: string | Uint8Array, encoding: BufferEncoding, callback?: () => void): void;
getHeader(name: string): string;
getHeaderNames(): string[];
getHeaders(): OutgoingHttpHeaders;
@ -661,7 +661,7 @@ declare module "http2" {
setHeader(name: string, value: number | string | string[]): void;
setTimeout(msecs: number, callback?: () => void): void;
write(chunk: string | Uint8Array, callback?: (err: Error) => void): boolean;
write(chunk: string | Uint8Array, encoding: string, callback?: (err: Error) => void): boolean;
write(chunk: string | Uint8Array, encoding: BufferEncoding, callback?: (err: Error) => void): boolean;
writeContinue(): void;
writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this;
writeHead(statusCode: number, statusMessage: string, headers?: OutgoingHttpHeaders): this;

View File

@ -3031,4 +3031,11 @@ declare module "inspector" {
* Return the URL of the active inspector, or `undefined` if there is none.
*/
function url(): string | undefined;
/**
* Blocks until a client (existing or connected later) has sent
* `Runtime.runIfWaitingForDebugger` command.
* An exception will be thrown if there is no active inspector.
*/
function waitForDebugger(): void;
}

6
types/node/net.d.ts vendored
View File

@ -58,14 +58,14 @@ declare module "net" {
// Extended base methods
write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
write(str: Uint8Array | string, encoding?: string, cb?: (err?: Error) => void): boolean;
write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error) => void): boolean;
connect(options: SocketConnectOpts, connectionListener?: () => void): this;
connect(port: number, host: string, connectionListener?: () => void): this;
connect(port: number, connectionListener?: () => void): this;
connect(path: string, connectionListener?: () => void): this;
setEncoding(encoding?: string): this;
setEncoding(encoding?: BufferEncoding): this;
pause(): this;
resume(): this;
setTimeout(timeout: number, callback?: () => void): this;
@ -89,7 +89,7 @@ declare module "net" {
// Extended base methods
end(cb?: () => void): void;
end(buffer: Uint8Array | string, cb?: () => void): void;
end(str: Uint8Array | string, encoding?: string, cb?: () => void): void;
end(str: Uint8Array | string, encoding?: BufferEncoding, cb?: () => void): void;
/**
* events.EventEmitter

2
types/node/os.d.ts vendored
View File

@ -49,7 +49,7 @@ declare module "os" {
function networkInterfaces(): NodeJS.Dict<NetworkInterfaceInfo[]>;
function homedir(): string;
function userInfo(options: { encoding: 'buffer' }): UserInfo<Buffer>;
function userInfo(options?: { encoding: string }): UserInfo<string>;
function userInfo(options?: { encoding: BufferEncoding }): UserInfo<string>;
type SignalConstants = {
[key in NodeJS.Signals]: number;

View File

@ -28,7 +28,7 @@ const httpsGet = (url: string) => new Promise<string>((resolve, reject) => {
// Input arguments
const tag = process.argv[2] || process.version;
const V8_PROTOCOL_URL = `https://raw.githubusercontent.com/nodejs/node/${tag}/deps/v8/src/inspector/js_protocol-1.3.json`;
const V8_PROTOCOL_URL = `https://raw.githubusercontent.com/nodejs/node/${tag}/deps/v8/include/js_protocol-1.3.json`;
const NODE_PROTOCOL_URL = `https://raw.githubusercontent.com/nodejs/node/${tag}/src/inspector/node_protocol.pdl`;
const INSPECTOR_PROTOCOL_REMOTE = `https://chromium.googlesource.com/deps/inspector_protocol`;
const INSPECTOR_PROTOCOL_LOCAL_DIR = "/tmp/inspector_protocol";

View File

@ -84,5 +84,5 @@ declare module "inspector" {
* `Runtime.runIfWaitingForDebugger` command.
* An exception will be thrown if there is no active inspector.
*/
waitForDebugger();
function waitForDebugger(): void;
}

View File

@ -12,7 +12,7 @@ declare module "stream" {
interface ReadableOptions {
highWaterMark?: number;
encoding?: string;
encoding?: BufferEncoding;
objectMode?: boolean;
read?(this: Readable, size: number): void;
destroy?(this: Readable, error: Error | null, callback: (error: Error | null) => void): void;
@ -33,14 +33,14 @@ declare module "stream" {
constructor(opts?: ReadableOptions);
_read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): this;
setEncoding(encoding: BufferEncoding): this;
pause(): this;
resume(): this;
isPaused(): boolean;
unpipe(destination?: NodeJS.WritableStream): this;
unshift(chunk: any, encoding?: BufferEncoding): void;
wrap(oldStream: NodeJS.ReadableStream): this;
push(chunk: any, encoding?: string): boolean;
push(chunk: any, encoding?: BufferEncoding): boolean;
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
destroy(error?: Error): void;
@ -124,11 +124,11 @@ declare module "stream" {
interface WritableOptions {
highWaterMark?: number;
decodeStrings?: boolean;
defaultEncoding?: string;
defaultencoding?: BufferEncoding;
objectMode?: boolean;
emitClose?: boolean;
write?(this: Writable, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
writev?(this: Writable, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
write?(this: Writable, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
writev?(this: Writable, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
destroy?(this: Writable, error: Error | null, callback: (error: Error | null) => void): void;
final?(this: Writable, callback: (error?: Error | null) => void): void;
autoDestroy?: boolean;
@ -144,16 +144,16 @@ declare module "stream" {
readonly writableCorked: number;
destroyed: boolean;
constructor(opts?: WritableOptions);
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
_writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
_writev?(chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
_final(callback: (error?: Error | null) => void): void;
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
write(chunk: any, encoding: string, cb?: (error: Error | null | undefined) => void): boolean;
setDefaultEncoding(encoding: string): this;
write(chunk: any, encoding: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
setDefaultEncoding(encoding: BufferEncoding): this;
end(cb?: () => void): void;
end(chunk: any, cb?: () => void): void;
end(chunk: any, encoding: string, cb?: () => void): void;
end(chunk: any, encoding: BufferEncoding, cb?: () => void): void;
cork(): void;
uncork(): void;
destroy(error?: Error): void;
@ -233,8 +233,8 @@ declare module "stream" {
writableHighWaterMark?: number;
writableCorked?: number;
read?(this: Duplex, size: number): void;
write?(this: Duplex, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
final?(this: Duplex, callback: (error?: Error | null) => void): void;
destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void;
}
@ -249,16 +249,16 @@ declare module "stream" {
readonly writableObjectMode: boolean;
readonly writableCorked: number;
constructor(opts?: DuplexOptions);
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
_writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
_writev?(chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
_destroy(error: Error | null, callback: (error: Error | null) => void): void;
_final(callback: (error?: Error | null) => void): void;
write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
write(chunk: any, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
setDefaultEncoding(encoding: string): this;
setDefaultEncoding(encoding: BufferEncoding): this;
end(cb?: () => void): void;
end(chunk: any, cb?: () => void): void;
end(chunk: any, encoding?: string, cb?: () => void): void;
end(chunk: any, encoding?: BufferEncoding, cb?: () => void): void;
cork(): void;
uncork(): void;
}
@ -267,17 +267,17 @@ declare module "stream" {
interface TransformOptions extends DuplexOptions {
read?(this: Transform, size: number): void;
write?(this: Transform, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
writev?(this: Transform, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
write?(this: Transform, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
writev?(this: Transform, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
final?(this: Transform, callback: (error?: Error | null) => void): void;
destroy?(this: Transform, error: Error | null, callback: (error: Error | null) => void): void;
transform?(this: Transform, chunk: any, encoding: string, callback: TransformCallback): void;
transform?(this: Transform, chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
flush?(this: Transform, callback: TransformCallback): void;
}
class Transform extends Duplex {
constructor(opts?: TransformOptions);
_transform(chunk: any, encoding: string, callback: TransformCallback): void;
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
_flush(callback: TransformCallback): void;
}

View File

@ -1,6 +1,6 @@
declare module "string_decoder" {
class StringDecoder {
constructor(encoding?: string);
constructor(encoding?: BufferEncoding);
write(buffer: Buffer): string;
end(buffer?: Buffer): string;
}

View File

@ -34,8 +34,8 @@ import * as util from 'util';
let content: string;
let buffer: Buffer;
let stringOrBuffer: string | Buffer;
const nullEncoding: string | null = null;
const stringEncoding: string | null = 'utf8';
const nullEncoding: BufferEncoding | null = null;
const stringEncoding: BufferEncoding | null = 'utf8';
content = fs.readFileSync('testfile', 'utf8');
content = fs.readFileSync('testfile', { encoding: 'utf8' });
@ -190,7 +190,6 @@ async function testPromisify() {
fs.readlink('/path/to/folder', { encoding: undefined }, (err, linkString) => s = linkString);
fs.readlink('/path/to/folder', { encoding: 'utf8' }, (err, linkString) => s = linkString);
fs.readlink('/path/to/folder', { encoding: 'buffer' }, (err, linkString) => b = linkString);
fs.readlink('/path/to/folder', { encoding: s }, (err, linkString) => typeof linkString === "string" ? s = linkString : b = linkString);
s = fs.readlinkSync('/path/to/folder');
s = fs.readlinkSync('/path/to/folder', undefined);
@ -203,8 +202,6 @@ async function testPromisify() {
s = fs.readlinkSync('/path/to/folder', { encoding: undefined });
s = fs.readlinkSync('/path/to/folder', { encoding: 'utf8' });
b = fs.readlinkSync('/path/to/folder', { encoding: 'buffer' });
const v2 = fs.readlinkSync('/path/to/folder', { encoding: s });
typeof v2 === "string" ? s = v2 : b = v2;
}
{
@ -219,7 +216,6 @@ async function testPromisify() {
fs.realpath('/path/to/folder', { encoding: undefined }, (err, resolvedPath) => s = resolvedPath);
fs.realpath('/path/to/folder', { encoding: 'utf8' }, (err, resolvedPath) => s = resolvedPath);
fs.realpath('/path/to/folder', { encoding: 'buffer' }, (err, resolvedPath) => b = resolvedPath);
fs.realpath('/path/to/folder', { encoding: s }, (err, resolvedPath) => typeof resolvedPath === "string" ? s = resolvedPath : b = resolvedPath);
s = fs.realpathSync('/path/to/folder');
s = fs.realpathSync('/path/to/folder', undefined);
@ -232,8 +228,6 @@ async function testPromisify() {
s = fs.realpathSync('/path/to/folder', { encoding: undefined });
s = fs.realpathSync('/path/to/folder', { encoding: 'utf8' });
b = fs.realpathSync('/path/to/folder', { encoding: 'buffer' });
const v2 = fs.realpathSync('/path/to/folder', { encoding: s });
typeof v2 === "string" ? s = v2 : b = v2;
// native
fs.realpath.native('/path/to/folder', (err, resolvedPath) => s = resolvedPath);
@ -245,7 +239,6 @@ async function testPromisify() {
fs.realpath.native('/path/to/folder', { encoding: undefined }, (err, resolvedPath) => s = resolvedPath);
fs.realpath.native('/path/to/folder', { encoding: 'utf8' }, (err, resolvedPath) => s = resolvedPath);
fs.realpath.native('/path/to/folder', { encoding: 'buffer' }, (err, resolvedPath) => b = resolvedPath);
fs.realpath.native('/path/to/folder', { encoding: s }, (err, resolvedPath) => typeof resolvedPath === "string" ? s = resolvedPath : b = resolvedPath);
s = fs.realpathSync.native('/path/to/folder');
s = fs.realpathSync.native('/path/to/folder', undefined);
@ -258,8 +251,6 @@ async function testPromisify() {
s = fs.realpathSync.native('/path/to/folder', { encoding: undefined });
s = fs.realpathSync.native('/path/to/folder', { encoding: 'utf8' });
b = fs.realpathSync.native('/path/to/folder', { encoding: 'buffer' });
const v4 = fs.realpathSync.native('/path/to/folder', { encoding: s });
typeof v4 === "string" ? s = v4 : b = v4;
}
{
@ -307,12 +298,10 @@ async function testPromisify() {
{
let names: Promise<string[]>;
let buffers: Promise<Buffer[]>;
let namesOrBuffers: Promise<string[] | Buffer[]>;
let entries: Promise<fs.Dirent[]>;
names = fs.promises.readdir('/path/to/dir', { encoding: 'utf8', withFileTypes: false });
buffers = fs.promises.readdir('/path/to/dir', { encoding: 'buffer', withFileTypes: false });
namesOrBuffers = fs.promises.readdir('/path/to/dir', { encoding: 'SOME OTHER', withFileTypes: false });
entries = fs.promises.readdir('/path/to/dir', { encoding: 'utf8', withFileTypes: true });
}

View File

@ -27,7 +27,7 @@ function simplified_stream_ctor_test() {
this;
// $ExpectType any
chunk;
// $ExpectType string
// $ExpectType BufferEncoding
enc;
// $ExpectType (error?: Error | null | undefined) => void
cb;
@ -35,7 +35,7 @@ function simplified_stream_ctor_test() {
writev(chunks, cb) {
// $ExpectType Writable
this;
// $ExpectType { chunk: any; encoding: string; }[]
// $ExpectType { chunk: any; encoding: BufferEncoding; }[]
chunks;
// $ExpectType (error?: Error | null | undefined) => void
cb;
@ -68,7 +68,7 @@ function simplified_stream_ctor_test() {
this;
// $ExpectType any
chunk;
// $ExpectType string
// $ExpectType BufferEncoding
enc;
// $ExpectType (error?: Error | null | undefined) => void
cb;
@ -76,7 +76,7 @@ function simplified_stream_ctor_test() {
writev(chunks, cb) {
// $ExpectType Duplex
this;
// $ExpectType { chunk: any; encoding: string; }[]
// $ExpectType { chunk: any; encoding: BufferEncoding; }[]
chunks;
// $ExpectType (error?: Error | null | undefined) => void
cb;
@ -113,7 +113,7 @@ function simplified_stream_ctor_test() {
this;
// $ExpectType any
chunk;
// $ExpectType string
// $ExpectType BufferEncoding
enc;
// $ExpectType (error?: Error | null | undefined) => void
cb;
@ -121,7 +121,7 @@ function simplified_stream_ctor_test() {
writev(chunks, cb) {
// $ExpectType Transform
this;
// $ExpectType { chunk: any; encoding: string; }[]
// $ExpectType { chunk: any; encoding: BufferEncoding; }[]
chunks;
// $ExpectType (error?: Error | null | undefined) => void
cb;
@ -145,7 +145,7 @@ function simplified_stream_ctor_test() {
this;
// $ExpectType any
chunk;
// $ExpectType string
// $ExpectType BufferEncoding
enc;
// $ExpectType TransformCallback
cb;

View File

@ -1,6 +1,6 @@
declare module "assert" {
function internal(value: any, message?: string | Error): void;
namespace internal {
function assert(value: any, message?: string | Error): void;
namespace assert {
class AssertionError implements Error {
name: string;
message: string;
@ -22,9 +22,13 @@ declare module "assert" {
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
function fail(actual: any, expected: any, message?: string | Error, operator?: string, stackStartFn?: Function): never;
function ok(value: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use strictEqual() instead. */
function equal(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notStrictEqual() instead. */
function notEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
function deepEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
function strictEqual(actual: any, expected: any, message?: string | Error): void;
function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
@ -46,8 +50,8 @@ declare module "assert" {
function match(value: string, regExp: RegExp, message?: string | Error): void;
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
const strict: typeof internal;
const strict: typeof assert;
}
export = internal;
export = assert;
}

View File

@ -1,6 +1,5 @@
// base definnitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="assert.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />

View File

@ -59,6 +59,9 @@
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />
// We can't include assert.d.ts in base.d.ts, as it'll cause duplication errors in +ts3.7
/// <reference path="assert.d.ts" />
// Forward-declarations for needed types from es2015 and later (in case users are using `--lib es5`)
// Empty interfaces are used here which merge fine with the real declarations in the lib XXX files
// just to ensure the names are known and node typings can be used without importing these libs.

View File

@ -2,6 +2,11 @@
"private": true,
"types": "index",
"typesVersions": {
">=3.7.0-0": {
"*": [
"ts3.7/*"
]
},
">=3.5.0-0": {
"*": [
"ts3.5/*"

22
types/node/v13/ts3.2/base.d.ts vendored Normal file
View File

@ -0,0 +1,22 @@
// NOTE: These definitions support NodeJS and TypeScript 3.2.
// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.1
// - ~/ts3.2/base.d.ts - Definitions specific to TypeScript 3.2
// - ~/ts3.2/index.d.ts - Definitions specific to TypeScript 3.2 with assert pulled in
// Reference required types from the default lib:
/// <reference lib="es2018" />
/// <reference lib="esnext.asynciterable" />
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.bigint" />
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
// tslint:disable-next-line:no-bad-reference
/// <reference path="../base.d.ts" />
// TypeScript 3.2-specific augmentations:
/// <reference path="fs.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="globals.d.ts" />

View File

@ -1,16 +1,8 @@
// NOTE: These definitions support NodeJS and TypeScript 3.2.
// This is requried to enable typing assert in ts3.7 without causing errors
// Typically type modifiations should be made in base.d.ts instead of here
// Reference required types from the default lib:
/// <reference lib="es2018" />
/// <reference lib="esnext.asynciterable" />
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.bigint" />
/// <reference path="base.d.ts" />
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
// tslint:disable-next-line:no-bad-reference
/// <reference path="../base.d.ts" />
// TypeScript 3.2-specific augmentations:
/// <reference path="fs.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="globals.d.ts" />
/// <reference path="../assert.d.ts" />

20
types/node/v13/ts3.5/base.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
// NOTE: These definitions support NodeJS and TypeScript 3.5.
// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.1
// - ~/ts3.5/base.d.ts - Definitions specific to TypeScript 3.5
// - ~/ts3.5/index.d.ts - Definitions specific to TypeScript 3.5 with assert pulled in
// Reference required types from the default lib:
/// <reference lib="es2018" />
/// <reference lib="esnext.asynciterable" />
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.bigint" />
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
// tslint:disable-next-line:no-bad-reference
/// <reference path="../ts3.2/base.d.ts" />
// TypeScript 3.5-specific augmentations:
/// <reference path="wasi.d.ts" />

View File

@ -1,14 +1,8 @@
// NOTE: These definitions support NodeJS and TypeScript 3.5.
// This is requried to enable typing assert in ts3.7 without causing errors
// Typically type modifiations should be made in base.d.ts instead of here
// Reference required types from the default lib:
/// <reference lib="es2018" />
/// <reference lib="esnext.asynciterable" />
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.bigint" />
/// <reference path="base.d.ts" />
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
// tslint:disable-next-line:no-bad-reference
/// <reference path="../ts3.2/index.d.ts" />
// TypeScript 3.5-specific augmentations:
/// <reference path="wasi.d.ts" />
/// <reference path="../assert.d.ts" />

57
types/node/v13/ts3.7/assert.d.ts vendored Normal file
View File

@ -0,0 +1,57 @@
declare module "assert" {
function assert(value: any, message?: string | Error): asserts value;
namespace assert {
class AssertionError implements Error {
name: string;
message: string;
actual: any;
expected: any;
operator: string;
generatedMessage: boolean;
code: 'ERR_ASSERTION';
constructor(options?: {
message?: string; actual?: any; expected?: any;
operator?: string; stackStartFn?: Function
});
}
type AssertPredicate = RegExp | (new() => object) | ((thrown: any) => boolean) | object | Error;
function fail(message?: string | Error): never;
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
function fail(actual: any, expected: any, message?: string | Error, operator?: string, stackStartFn?: Function): never;
function ok(value: any, message?: string | Error): asserts value;
/** @deprecated since v9.9.0 - use strictEqual() instead. */
function equal(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notStrictEqual() instead. */
function notEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
function deepEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
function strictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
function deepStrictEqual<T>(actual: any, expected: T, message?: string | Error): asserts actual is T;
function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function throws(block: () => any, message?: string | Error): void;
function throws(block: () => any, error: AssertPredicate, message?: string | Error): void;
function doesNotThrow(block: () => any, message?: string | Error): void;
function doesNotThrow(block: () => any, error: RegExp | Function, message?: string | Error): void;
function ifError(value: any): asserts value is null | undefined;
function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
function rejects(block: (() => Promise<any>) | Promise<any>, error: AssertPredicate, message?: string | Error): Promise<void>;
function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
function doesNotReject(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function, message?: string | Error): Promise<void>;
function match(value: string, regExp: RegExp, message?: string | Error): void;
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
const strict: typeof assert;
}
export = assert;
}

20
types/node/v13/ts3.7/base.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
// NOTE: These definitions support NodeJS and TypeScript 3.7.
// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.1
// - ~/ts3.7/base.d.ts - Definitions specific to TypeScript 3.7
// - ~/ts3.7/index.d.ts - Definitions specific to TypeScript 3.7 with assert pulled in
// Reference required types from the default lib:
/// <reference lib="es2018" />
/// <reference lib="esnext.asynciterable" />
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.bigint" />
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
// tslint:disable-next-line:no-bad-reference
/// <reference path="../ts3.5/base.d.ts" />
// TypeScript 3.7-specific augmentations:
/// <reference path="assert.d.ts" />

5
types/node/v13/ts3.7/index.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
// NOTE: These definitions support NodeJS and TypeScript 3.7.
// This isn't strictly needed since 3.7 has the assert module, but this way we're consistent.
// Typically type modificatons should be made in base.d.ts instead of here
/// <reference path="base.d.ts" />

View File

@ -0,0 +1,59 @@
import * as assert from 'assert';
assert(true, "it's working");
assert.ok(true, 'inner functions work as well');
assert.throws(() => {});
assert.throws(() => {}, /Regex test/);
assert.throws(
() => {},
() => {},
'works wonderfully',
);
assert['fail'](true, true, 'works like a charm');
{
const a = null as any;
assert.ifError(a);
a; // $ExpectType null | undefined
}
{
const a = true as boolean;
assert(a);
a; // $ExpectType true
}
{
// tslint:disable-next-line: no-null-undefined-union
const a = 13 as number | null | undefined;
assert(a);
a; // $ExpectType number
}
{
const a = true as boolean;
assert.ok(a);
a; // $ExpectType true
}
{
// tslint:disable-next-line: no-null-undefined-union
const a = 13 as number | null | undefined;
assert.ok(a);
a; // $ExpectType number
}
{
const a = 'test' as any;
assert.strictEqual(a, 'test');
a; // $ExpectType string
}
{
const a = { b: 2 } as any;
assert.deepStrictEqual(a, { b: 2 });
a; // $ExpectType { b: number; }
}

View File

@ -0,0 +1,30 @@
{
"files": [
"index.d.ts",
"node-tests.ts"
],
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../../",
"typeRoots": [
"../../../"
],
"paths": {
"node": [
"node/v13"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}

View File

@ -0,0 +1,10 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false,
"unified-signatures": false,
"no-empty-interface": false,
"no-single-declare-module": false,
"strict-export-declare-modifiers": false // http2 needs this
}
}

View File

@ -4,8 +4,8 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface IStream {
update?(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
write?(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
update?(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
write?(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
}
import HashStatic = ObjectHash.HashStatic;

View File

@ -1,4 +1,4 @@
import readJsonSync = require("read-json-sync");
readJsonSync("file.json", "utf8");
readJsonSync(1, { encoding: "gb2312" });
readJsonSync(1, { encoding: "utf8" });

View File

@ -6,7 +6,6 @@
/// <reference types="node" />
import * as events from "events";
import * as stream from "stream";
import * as SafeBuffer from "safe-buffer";
import { StringDecoder } from "string_decoder";
@ -54,8 +53,8 @@ declare namespace _Readable {
readable?: boolean;
writable?: boolean;
read?(this: Duplex, size: number): void;
write?(this: Duplex, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
final?(this: Duplex, callback: (error?: Error | null) => void): void;
destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void;
};
@ -77,14 +76,14 @@ declare namespace _Readable {
_read(size?: number): void;
read(size?: number): any;
setEncoding(enc: string): this;
setEncoding(enc: BufferEncoding): this;
resume(): this;
pause(): this;
isPaused(): boolean;
unpipe(dest?: NodeJS.WritableStream): this;
unshift(chunk: any): boolean;
wrap(oldStream: NodeJS.ReadableStream): this;
push(chunk: any, encoding?: string): boolean;
push(chunk: any, encoding?: BufferEncoding): boolean;
_destroy(err: Error | null, callback: (error: Error | null) => void): void;
destroy(err?: Error, callback?: (error: Error | null) => void): this;
pipe<S extends NodeJS.WritableStream>(dest: S, pipeOpts?: { end?: boolean }): S;
@ -102,13 +101,13 @@ declare namespace _Readable {
class PassThrough extends Transform implements stream.PassThrough {
constructor(options?: TransformOptions);
_transform<T>(chunk: T, encoding: string | null | undefined, callback: (error: any, data: T) => void): void;
_transform<T>(chunk: T, encoding: BufferEncoding | null | undefined, callback: (error: any, data: T) => void): void;
}
// ==== _stream_readable ====
interface ReadableStateOptions {
defaultEncoding?: string;
encoding?: string;
defaultEncoding?: BufferEncoding;
encoding?: BufferEncoding;
highWaterMark?: number;
objectMode?: boolean;
readableObjectMode?: boolean;
@ -133,10 +132,10 @@ declare namespace _Readable {
resumeScheduled: boolean;
destroyed: boolean;
awaitDrain: number;
defaultEncoding: string;
defaultEncoding: BufferEncoding;
readingMore: boolean;
decoder: StringDecoder | null;
encoding: string | null;
encoding: BufferEncoding | null;
// new (options: ReadableStateOptions, stream: _Readable): ReadableState;
}
@ -153,11 +152,11 @@ declare namespace _Readable {
// ==== _stream_transform ====
type TransformOptions = DuplexOptions & {
read?(this: Transform, size: number): void;
write?(this: Transform, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
writev?(this: Transform, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
write?(this: Transform, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
writev?(this: Transform, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
final?(this: Transform, callback: (error?: Error | null) => void): void;
destroy?(this: Transform, error: Error | null, callback: (error: Error | null) => void): void;
transform?(this: Transform, chunk: any, encoding: string, callback: (error?: Error, data?: any) => void): void;
transform?(this: Transform, chunk: any, encoding: BufferEncoding, callback: (error?: Error, data?: any) => void): void;
flush?(this: Transform, callback: (er: any, data: any) => void): void;
};
@ -168,12 +167,12 @@ declare namespace _Readable {
transforming: boolean;
writecb: ((err: any) => any) | null;
writechunk: any; // TODO
writeencoding: string | null;
writeencoding: BufferEncoding | null;
};
constructor(options?: TransformOptions);
_transform(chunk: any, encoding: string, callback: (error?: Error, data?: any) => void): void;
_transform(chunk: any, encoding: BufferEncoding, callback: (error?: Error, data?: any) => void): void;
_flush(callback: (error?: Error, data?: any) => void): void;
}
@ -186,7 +185,7 @@ declare namespace _Readable {
interface BufferRequest {
chunk: any; // TODO
encoding: string;
encoding: BufferEncoding;
isBuf: boolean;
callback: (error?: Error | null) => void;
next: BufferRequest | null;
@ -194,7 +193,7 @@ declare namespace _Readable {
interface WritableStateOptions {
decodeStrings?: boolean;
defaultEncoding?: string;
defaultEncoding?: BufferEncoding;
highWaterMark?: number;
objectMode?: boolean;
writableObjectMode?: boolean;
@ -212,7 +211,7 @@ declare namespace _Readable {
finished: boolean;
destroyed: boolean;
decodeStrings: boolean;
defaultEncoding: string;
defaultEncoding: BufferEncoding;
length: number;
writing: boolean;
corked: number;
@ -235,8 +234,8 @@ declare namespace _Readable {
}
type WritableOptions = WritableStateOptions & {
write?(this: Writable, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
writev?(this: Writable, chunk: ArrayLike<{ chunk: any; encoding: string }>, callback: (error?: Error | null) => void): void;
write?(this: Writable, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
writev?(this: Writable, chunk: ArrayLike<{ chunk: any; encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
destroy?(this: Writable, error: Error | null, callback: (error: Error | null) => void): void;
final?(this: Writable, callback: (error?: Error | null) => void): void;
};

View File

@ -115,7 +115,7 @@ declare namespace resolve {
export interface SyncOpts extends Opts {
/** how to read files synchronously (defaults to fs.readFileSync) */
readFileSync?: (file: string, charset: string) => string | Buffer;
readFileSync?: (file: string, encoding: BufferEncoding) => string | Buffer;
/** function to synchronously test whether a file exists */
isFile?: (file: string) => boolean;
/** function to synchronously test whether a directory exists */

View File

@ -13,7 +13,7 @@ snappy.uncompress(data, (err, data) => {
if (err) {
throw err;
}
console.log(data.toString('UTF8'));
console.log(data.toString('utf8'));
});
snappy.uncompress(otherData, { asBuffer: false }, (err, original) => {
if (err) {

View File

@ -5,7 +5,7 @@ import snekfetch = require('snekfetch');
const writeFile = util.promisify(fs.writeFile);
snekfetch.get('https://s.gus.host/o-SNAKES-80.jpg')
.then(r => writeFile('download.jpg', r.body));
.then(r => writeFile('download.jpg', r.body as (string | Buffer)));
snekfetch.get('https://s.gus.host/o-SNAKES-80.jpg')
.pipe(fs.createWriteStream('download.jpg'));

View File

@ -22,7 +22,7 @@ declare namespace through2 {
}
type TransformCallback = (err?: any, data?: any) => void;
type TransformFunction = (this: stream.Transform, chunk: any, enc: string, callback: TransformCallback) => void;
type TransformFunction = (this: stream.Transform, chunk: any, enc: BufferEncoding, callback: TransformCallback) => void;
type FlushCallback = (this: stream.Transform, flushCallback: () => void) => void;
/**

View File

@ -24,8 +24,7 @@ rws = through2(function (entry: any, enc: string, callback: () => void) {
});
rws = through2(function (entry, enc, callback) {
var str: string = enc;
this.push(entry, str);
this.push(entry, enc);
callback(null, 'continue');
}, () => {