flip node typesVersions

This commit is contained in:
Nathan Shively-Sanders 2020-08-19 11:30:57 -07:00
parent c5a73ab9db
commit 5b6137d6c9
197 changed files with 9493 additions and 9493 deletions

View File

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): void;
function assert(value: any, message?: string | Error): asserts value;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,20 +19,20 @@ declare module "assert" {
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. */
/** @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 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. */
/** @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. */
/** @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. */
/** @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 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(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;
@ -40,7 +40,7 @@ declare module "assert" {
function doesNotThrow(block: () => any, message?: string | Error): void;
function doesNotThrow(block: () => any, error: RegExp | Function, message?: string | Error): void;
function ifError(value: any): 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>;

61
types/node/base.d.ts vendored
View File

@ -1,41 +1,20 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="fs/promises.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />
// 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" />

92
types/node/index.d.ts vendored
View File

@ -1,91 +1,5 @@
// Type definitions for non-npm package Node.js 14.6
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Benjamin Toueg <https://github.com/btoueg>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// David Junger <https://github.com/touffy>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Marcin Kopacz <https://github.com/chyzwar>
// Trivikram Kamat <https://github.com/trivikr>
// Minh Son Nguyen <https://github.com/nguymin4>
// Junxiao Shi <https://github.com/yoursunny>
// Ilia Baryshnikov <https://github.com/qwelias>
// ExE Boss <https://github.com/ExE-Boss>
// Surasak Chaisurin <https://github.com/Ryan-Willpower>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Anna Henningsen <https://github.com/addaleax>
// Jason Kwok <https://github.com/JasonHK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// 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
// 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.8
// - ~/ts3.5/index.d.ts - Definitions specific to TypeScript 3.5
// NOTE: Augmentations for TypeScript 3.5 and later should use individual files for overrides
// within the respective ~/ts3.5 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.5, so the older definitions will be found here.
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />
// We can't include globals.global.d.ts in globals.d.ts, as it'll cause duplication errors in TypeScript 3.5+
/// <reference path="globals.global.d.ts" />
// We can't include assert.d.ts in base.d.ts, as it'll cause duplication errors in TypeScript 3.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.
// if someone really needs these types the libs need to be added via --lib or in tsconfig.json
interface AsyncIterable<T> { }
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
// even this is just a forward declaration some properties are added otherwise
// it would be allowed to pass anything to e.g. Buffer.from()
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

View File

@ -1,351 +1,59 @@
import * as fs from "fs";
import * as url from "url";
import * as util from "util";
import * as http from "http";
import * as https from "https";
import * as net from "net";
import * as console2 from "console";
import * as timers from "timers";
import * as inspector from "inspector";
import * as trace_events from "trace_events";
import * as assert from 'assert';
//////////////////////////////////////////////////////
/// Https tests : http://nodejs.org/api/https.html ///
//////////////////////////////////////////////////////
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');
{
let agent: https.Agent = new https.Agent({
keepAlive: true,
keepAliveMsecs: 10000,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
timeout: 15000
});
agent = https.globalAgent;
let sockets: NodeJS.ReadOnlyDict<net.Socket[]> = agent.sockets;
sockets = agent.freeSockets;
https.request({
agent: false
});
https.request({
agent
});
https.request({
agent: undefined
});
https.get('http://www.example.com/xyz');
https.request('http://www.example.com/xyz');
https.get('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.request('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.get(new url.URL('http://www.example.com/xyz'));
https.request(new url.URL('http://www.example.com/xyz'));
https.get(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
const opts: https.RequestOptions = {
path: '/some/path'
};
https.get(new url.URL('http://www.example.com'), opts);
https.request(new url.URL('http://www.example.com'), opts);
https.get(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.globalAgent.options.ca = [];
{
function reqListener(req: http.IncomingMessage, res: http.ServerResponse): void {}
class MyIncomingMessage extends http.IncomingMessage {
foo: number;
}
class MyServerResponse extends http.ServerResponse {
foo: string;
}
let server: https.Server;
server = new https.Server();
server = new https.Server(reqListener);
server = new https.Server({ IncomingMessage: MyIncomingMessage});
server = new https.Server({
IncomingMessage: MyIncomingMessage,
ServerResponse: MyServerResponse
}, reqListener);
server = https.createServer();
server = https.createServer(reqListener);
server = https.createServer({ IncomingMessage: MyIncomingMessage });
server = https.createServer({ ServerResponse: MyServerResponse }, reqListener);
const timeout: number = server.timeout;
const listening: boolean = server.listening;
const keepAliveTimeout: number = server.keepAliveTimeout;
const maxHeadersCount: number | null = server.maxHeadersCount;
const headersTimeout: number = server.headersTimeout;
server.setTimeout().setTimeout(1000).setTimeout(() => {}).setTimeout(100, () => {});
}
const a = null as any;
assert.ifError(a);
a; // $ExpectType null | undefined
}
/////////////////////////////////////////////////////
/// Timers tests : https://nodejs.org/api/timers.html
/////////////////////////////////////////////////////
{
{
const immediate = timers
.setImmediate(() => {
console.log('immediate');
})
.unref()
.ref();
const b: boolean = immediate.hasRef();
timers.clearImmediate(immediate);
}
{
const timeout = timers
.setInterval(() => {
console.log('interval');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearInterval(timeout);
}
{
const timeout = timers
.setTimeout(() => {
console.log('timeout');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearTimeout(timeout);
}
async function testPromisify(doSomething: {
(foo: any, onSuccessCallback: (result: string) => void, onErrorCallback: (reason: any) => void): void;
[util.promisify.custom](foo: any): Promise<string>;
}) {
const setTimeout = util.promisify(timers.setTimeout);
let v: void = await setTimeout(100); // tslint:disable-line no-void-expression void-return
let s: string = await setTimeout(100, "");
const setImmediate = util.promisify(timers.setImmediate);
v = await setImmediate(); // tslint:disable-line no-void-expression
s = await setImmediate("");
// $ExpectType (foo: any) => Promise<string>
const doSomethingPromise = util.promisify(doSomething);
// $ExpectType string
s = await doSomethingPromise('foo');
}
const a = true as boolean;
assert(a);
a; // $ExpectType true
}
/////////////////////////////////////////////////////////
/// Errors Tests : https://nodejs.org/api/errors.html ///
/////////////////////////////////////////////////////////
{
{
Error.stackTraceLimit = Infinity;
}
{
const myObject = {};
Error.captureStackTrace(myObject);
}
{
const frames: NodeJS.CallSite[] = [];
Error.prepareStackTrace!(new Error(), frames);
}
{
const frame: NodeJS.CallSite = null!;
const frameThis: any = frame.getThis();
const typeName: string | null = frame.getTypeName();
const func: Function | undefined = frame.getFunction();
const funcName: string | null = frame.getFunctionName();
const meth: string | null = frame.getMethodName();
const fname: string | null = frame.getFileName();
const lineno: number | null = frame.getLineNumber();
const colno: number | null = frame.getColumnNumber();
const evalOrigin: string | undefined = frame.getEvalOrigin();
const isTop: boolean = frame.isToplevel();
const isEval: boolean = frame.isEval();
const isNative: boolean = frame.isNative();
const isConstr: boolean = frame.isConstructor();
}
// tslint:disable-next-line: no-null-undefined-union
const a = 13 as number | null | undefined;
assert(a);
a; // $ExpectType number
}
///////////////////////////////////////////////////////////
/// Console Tests : https://nodejs.org/api/console.html ///
///////////////////////////////////////////////////////////
{
{
let _c: Console = console;
_c = console2;
}
{
const writeStream = fs.createWriteStream('./index.d.ts');
let consoleInstance: Console = new console.Console(writeStream);
consoleInstance = new console.Console(writeStream, writeStream);
consoleInstance = new console.Console(writeStream, writeStream, true);
consoleInstance = new console.Console({
stdout: writeStream,
stderr: writeStream,
colorMode: 'auto',
ignoreErrors: true
});
consoleInstance = new console.Console({
stdout: writeStream,
colorMode: false
});
consoleInstance = new console.Console({
stdout: writeStream
});
}
{
console.assert('value');
console.assert('value', 'message');
console.assert('value', 'message', 'foo', 'bar');
console.clear();
console.count();
console.count('label');
console.countReset();
console.countReset('label');
console.debug();
console.debug('message');
console.debug('message', 'foo', 'bar');
console.dir('obj');
console.dir('obj', { depth: 1 });
console.error();
console.error('message');
console.error('message', 'foo', 'bar');
console.group();
console.group('label');
console.group('label1', 'label2');
console.groupCollapsed();
console.groupEnd();
console.info();
console.info('message');
console.info('message', 'foo', 'bar');
console.log();
console.log('message');
console.log('message', 'foo', 'bar');
console.table({ foo: 'bar' });
console.table([{ foo: 'bar' }]);
console.table([{ foo: 'bar' }], ['foo']);
console.time();
console.time('label');
console.timeEnd();
console.timeEnd('label');
console.timeLog();
console.timeLog('label');
console.timeLog('label', 'foo', 'bar');
console.trace();
console.trace('message');
console.trace('message', 'foo', 'bar');
console.warn();
console.warn('message');
console.warn('message', 'foo', 'bar');
// --- Inspector mode only ---
console.profile();
console.profile('label');
console.profileEnd();
console.profileEnd('label');
console.timeStamp();
console.timeStamp('label');
}
const a = true as boolean;
assert.ok(a);
a; // $ExpectType true
}
/*****************************************************************************
* *
* The following tests are the modules not mentioned in document but existed *
* *
*****************************************************************************/
///////////////////////////////////////////////////////////
/// Inspector Tests ///
///////////////////////////////////////////////////////////
{
{
const b: inspector.Console.ConsoleMessage = {source: 'test', text: 'test', level: 'error' };
inspector.open();
inspector.open(0);
inspector.open(0, 'localhost');
inspector.open(0, 'localhost', true);
inspector.close();
const inspectorUrl: string | undefined = inspector.url();
const session = new inspector.Session();
session.connect();
session.disconnect();
// Unknown post method
session.post('A.b', { key: 'value' }, (err, params) => {});
// TODO: parameters are implicitly 'any' and need type annotation
session.post('A.b', (err: Error | null, params?: {}) => {});
session.post('A.b');
// Known post method
const parameter: inspector.Runtime.EvaluateParameterType = { expression: '2 + 2' };
session.post('Runtime.evaluate', parameter,
(err: Error | null, params: inspector.Runtime.EvaluateReturnType) => {});
session.post('Runtime.evaluate', (err: Error, params: inspector.Runtime.EvaluateReturnType) => {
const exceptionDetails: inspector.Runtime.ExceptionDetails = params.exceptionDetails!;
const resultClassName: string = params.result.className!;
});
session.post('Runtime.evaluate');
// General event
session.on('inspectorNotification', message => {
message; // $ExpectType InspectorNotification<{}>
});
// Known events
session.on('Debugger.paused', (message: inspector.InspectorNotification<inspector.Debugger.PausedEventDataType>) => {
const method: string = message.method;
const pauseReason: string = message.params.reason;
});
session.on('Debugger.resumed', () => {});
// Node Inspector events
session.on('NodeTracing.dataCollected', (message: inspector.InspectorNotification<inspector.NodeTracing.DataCollectedEventDataType>) => {
const value: Array<{}> = message.params.value;
});
}
// tslint:disable-next-line: no-null-undefined-union
const a = 13 as number | null | undefined;
assert.ok(a);
a; // $ExpectType number
}
///////////////////////////////////////////////////////////
/// Trace Events Tests ///
///////////////////////////////////////////////////////////
{
const enabledCategories: string | undefined = trace_events.getEnabledCategories();
const tracing: trace_events.Tracing = trace_events.createTracing({ categories: ['node', 'v8'] });
const categories: string = tracing.categories;
const enabled: boolean = tracing.enabled;
tracing.enable();
tracing.disable();
const a = 'test' as any;
assert.strictEqual(a, 'test');
a; // $ExpectType string
}
////////////////////////////////////////////////////
/// Node.js ESNEXT Support
////////////////////////////////////////////////////
{
const s = 'foo';
const s1: string = s.trimLeft();
const s2: string = s.trimRight();
const a = { b: 2 } as any;
assert.deepStrictEqual(a, { b: 2 });
a; // $ExpectType { b: number; }
}

View File

@ -2,19 +2,19 @@
"private": true,
"types": "index",
"typesVersions": {
">=3.7.0-0": {
"<=3.1": {
"*": [
"ts3.7/*"
"ts3.1/*"
]
},
">=3.5.0-0": {
"<=3.4": {
"*": [
"ts3.5/*"
"ts3.4/*"
]
},
">=3.2.0-0": {
"<=3.6": {
"*": [
"ts3.2/*"
"ts3.6/*"
]
}
}

View File

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): asserts value;
function assert(value: any, message?: string | Error): void;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,20 +19,20 @@ declare module "assert" {
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. */
/** @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 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. */
/** @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. */
/** @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. */
/** @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 strictEqual(actual: any, expected: any, message?: string | Error): void;
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 deepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function throws(block: () => any, message?: string | Error): void;
@ -40,7 +40,7 @@ declare module "assert" {
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 ifError(value: any): void;
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>;

41
types/node/ts3.1/base.d.ts vendored Normal file
View File

@ -0,0 +1,41 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="fs/promises.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />

91
types/node/ts3.1/index.d.ts vendored Normal file
View File

@ -0,0 +1,91 @@
// Type definitions for non-npm package Node.js 14.6
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Benjamin Toueg <https://github.com/btoueg>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// David Junger <https://github.com/touffy>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Marcin Kopacz <https://github.com/chyzwar>
// Trivikram Kamat <https://github.com/trivikr>
// Minh Son Nguyen <https://github.com/nguymin4>
// Junxiao Shi <https://github.com/yoursunny>
// Ilia Baryshnikov <https://github.com/qwelias>
// ExE Boss <https://github.com/ExE-Boss>
// Surasak Chaisurin <https://github.com/Ryan-Willpower>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Anna Henningsen <https://github.com/addaleax>
// Jason Kwok <https://github.com/JasonHK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// 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.8
// - ~/ts3.5/index.d.ts - Definitions specific to TypeScript 3.5
// NOTE: Augmentations for TypeScript 3.5 and later should use individual files for overrides
// within the respective ~/ts3.5 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.5, so the older definitions will be found here.
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />
// We can't include globals.global.d.ts in globals.d.ts, as it'll cause duplication errors in TypeScript 3.5+
/// <reference path="globals.global.d.ts" />
// We can't include assert.d.ts in base.d.ts, as it'll cause duplication errors in TypeScript 3.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.
// if someone really needs these types the libs need to be added via --lib or in tsconfig.json
interface AsyncIterable<T> { }
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
// even this is just a forward declaration some properties are added otherwise
// it would be allowed to pass anything to e.g. Buffer.from()
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

View File

@ -0,0 +1,351 @@
import * as fs from "fs";
import * as url from "url";
import * as util from "util";
import * as http from "http";
import * as https from "https";
import * as net from "net";
import * as console2 from "console";
import * as timers from "timers";
import * as inspector from "inspector";
import * as trace_events from "trace_events";
//////////////////////////////////////////////////////
/// Https tests : http://nodejs.org/api/https.html ///
//////////////////////////////////////////////////////
{
let agent: https.Agent = new https.Agent({
keepAlive: true,
keepAliveMsecs: 10000,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
timeout: 15000
});
agent = https.globalAgent;
let sockets: NodeJS.ReadOnlyDict<net.Socket[]> = agent.sockets;
sockets = agent.freeSockets;
https.request({
agent: false
});
https.request({
agent
});
https.request({
agent: undefined
});
https.get('http://www.example.com/xyz');
https.request('http://www.example.com/xyz');
https.get('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.request('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.get(new url.URL('http://www.example.com/xyz'));
https.request(new url.URL('http://www.example.com/xyz'));
https.get(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
const opts: https.RequestOptions = {
path: '/some/path'
};
https.get(new url.URL('http://www.example.com'), opts);
https.request(new url.URL('http://www.example.com'), opts);
https.get(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.globalAgent.options.ca = [];
{
function reqListener(req: http.IncomingMessage, res: http.ServerResponse): void {}
class MyIncomingMessage extends http.IncomingMessage {
foo: number;
}
class MyServerResponse extends http.ServerResponse {
foo: string;
}
let server: https.Server;
server = new https.Server();
server = new https.Server(reqListener);
server = new https.Server({ IncomingMessage: MyIncomingMessage});
server = new https.Server({
IncomingMessage: MyIncomingMessage,
ServerResponse: MyServerResponse
}, reqListener);
server = https.createServer();
server = https.createServer(reqListener);
server = https.createServer({ IncomingMessage: MyIncomingMessage });
server = https.createServer({ ServerResponse: MyServerResponse }, reqListener);
const timeout: number = server.timeout;
const listening: boolean = server.listening;
const keepAliveTimeout: number = server.keepAliveTimeout;
const maxHeadersCount: number | null = server.maxHeadersCount;
const headersTimeout: number = server.headersTimeout;
server.setTimeout().setTimeout(1000).setTimeout(() => {}).setTimeout(100, () => {});
}
}
/////////////////////////////////////////////////////
/// Timers tests : https://nodejs.org/api/timers.html
/////////////////////////////////////////////////////
{
{
const immediate = timers
.setImmediate(() => {
console.log('immediate');
})
.unref()
.ref();
const b: boolean = immediate.hasRef();
timers.clearImmediate(immediate);
}
{
const timeout = timers
.setInterval(() => {
console.log('interval');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearInterval(timeout);
}
{
const timeout = timers
.setTimeout(() => {
console.log('timeout');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearTimeout(timeout);
}
async function testPromisify(doSomething: {
(foo: any, onSuccessCallback: (result: string) => void, onErrorCallback: (reason: any) => void): void;
[util.promisify.custom](foo: any): Promise<string>;
}) {
const setTimeout = util.promisify(timers.setTimeout);
let v: void = await setTimeout(100); // tslint:disable-line no-void-expression void-return
let s: string = await setTimeout(100, "");
const setImmediate = util.promisify(timers.setImmediate);
v = await setImmediate(); // tslint:disable-line no-void-expression
s = await setImmediate("");
// $ExpectType (foo: any) => Promise<string>
const doSomethingPromise = util.promisify(doSomething);
// $ExpectType string
s = await doSomethingPromise('foo');
}
}
/////////////////////////////////////////////////////////
/// Errors Tests : https://nodejs.org/api/errors.html ///
/////////////////////////////////////////////////////////
{
{
Error.stackTraceLimit = Infinity;
}
{
const myObject = {};
Error.captureStackTrace(myObject);
}
{
const frames: NodeJS.CallSite[] = [];
Error.prepareStackTrace!(new Error(), frames);
}
{
const frame: NodeJS.CallSite = null!;
const frameThis: any = frame.getThis();
const typeName: string | null = frame.getTypeName();
const func: Function | undefined = frame.getFunction();
const funcName: string | null = frame.getFunctionName();
const meth: string | null = frame.getMethodName();
const fname: string | null = frame.getFileName();
const lineno: number | null = frame.getLineNumber();
const colno: number | null = frame.getColumnNumber();
const evalOrigin: string | undefined = frame.getEvalOrigin();
const isTop: boolean = frame.isToplevel();
const isEval: boolean = frame.isEval();
const isNative: boolean = frame.isNative();
const isConstr: boolean = frame.isConstructor();
}
}
///////////////////////////////////////////////////////////
/// Console Tests : https://nodejs.org/api/console.html ///
///////////////////////////////////////////////////////////
{
{
let _c: Console = console;
_c = console2;
}
{
const writeStream = fs.createWriteStream('./index.d.ts');
let consoleInstance: Console = new console.Console(writeStream);
consoleInstance = new console.Console(writeStream, writeStream);
consoleInstance = new console.Console(writeStream, writeStream, true);
consoleInstance = new console.Console({
stdout: writeStream,
stderr: writeStream,
colorMode: 'auto',
ignoreErrors: true
});
consoleInstance = new console.Console({
stdout: writeStream,
colorMode: false
});
consoleInstance = new console.Console({
stdout: writeStream
});
}
{
console.assert('value');
console.assert('value', 'message');
console.assert('value', 'message', 'foo', 'bar');
console.clear();
console.count();
console.count('label');
console.countReset();
console.countReset('label');
console.debug();
console.debug('message');
console.debug('message', 'foo', 'bar');
console.dir('obj');
console.dir('obj', { depth: 1 });
console.error();
console.error('message');
console.error('message', 'foo', 'bar');
console.group();
console.group('label');
console.group('label1', 'label2');
console.groupCollapsed();
console.groupEnd();
console.info();
console.info('message');
console.info('message', 'foo', 'bar');
console.log();
console.log('message');
console.log('message', 'foo', 'bar');
console.table({ foo: 'bar' });
console.table([{ foo: 'bar' }]);
console.table([{ foo: 'bar' }], ['foo']);
console.time();
console.time('label');
console.timeEnd();
console.timeEnd('label');
console.timeLog();
console.timeLog('label');
console.timeLog('label', 'foo', 'bar');
console.trace();
console.trace('message');
console.trace('message', 'foo', 'bar');
console.warn();
console.warn('message');
console.warn('message', 'foo', 'bar');
// --- Inspector mode only ---
console.profile();
console.profile('label');
console.profileEnd();
console.profileEnd('label');
console.timeStamp();
console.timeStamp('label');
}
}
/*****************************************************************************
* *
* The following tests are the modules not mentioned in document but existed *
* *
*****************************************************************************/
///////////////////////////////////////////////////////////
/// Inspector Tests ///
///////////////////////////////////////////////////////////
{
{
const b: inspector.Console.ConsoleMessage = {source: 'test', text: 'test', level: 'error' };
inspector.open();
inspector.open(0);
inspector.open(0, 'localhost');
inspector.open(0, 'localhost', true);
inspector.close();
const inspectorUrl: string | undefined = inspector.url();
const session = new inspector.Session();
session.connect();
session.disconnect();
// Unknown post method
session.post('A.b', { key: 'value' }, (err, params) => {});
// TODO: parameters are implicitly 'any' and need type annotation
session.post('A.b', (err: Error | null, params?: {}) => {});
session.post('A.b');
// Known post method
const parameter: inspector.Runtime.EvaluateParameterType = { expression: '2 + 2' };
session.post('Runtime.evaluate', parameter,
(err: Error | null, params: inspector.Runtime.EvaluateReturnType) => {});
session.post('Runtime.evaluate', (err: Error, params: inspector.Runtime.EvaluateReturnType) => {
const exceptionDetails: inspector.Runtime.ExceptionDetails = params.exceptionDetails!;
const resultClassName: string = params.result.className!;
});
session.post('Runtime.evaluate');
// General event
session.on('inspectorNotification', message => {
message; // $ExpectType InspectorNotification<{}>
});
// Known events
session.on('Debugger.paused', (message: inspector.InspectorNotification<inspector.Debugger.PausedEventDataType>) => {
const method: string = message.method;
const pauseReason: string = message.params.reason;
});
session.on('Debugger.resumed', () => {});
// Node Inspector events
session.on('NodeTracing.dataCollected', (message: inspector.InspectorNotification<inspector.NodeTracing.DataCollectedEventDataType>) => {
const value: Array<{}> = message.params.value;
});
}
}
///////////////////////////////////////////////////////////
/// Trace Events Tests ///
///////////////////////////////////////////////////////////
{
const enabledCategories: string | undefined = trace_events.getEnabledCategories();
const tracing: trace_events.Tracing = trace_events.createTracing({ categories: ['node', 'v8'] });
const categories: string = tracing.categories;
const enabled: boolean = tracing.enabled;
tracing.enable();
tracing.disable();
}
////////////////////////////////////////////////////
/// Node.js ESNEXT Support
////////////////////////////////////////////////////
{
const s = 'foo';
const s1: string = s.trimLeft();
const s2: string = s.trimRight();
}

View File

@ -0,0 +1,10 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false,
"no-empty-interface": false,
"no-single-declare-module": false,
"no-unnecessary-class": false,
"unified-signatures": false
}
}

View File

@ -1,20 +0,0 @@
// 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" />

View File

@ -1,5 +0,0 @@
// 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

@ -1,59 +0,0 @@
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

@ -1,10 +1,10 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false,
"no-empty-interface": false,
"no-single-declare-module": false,
"no-unnecessary-class": false,
"unified-signatures": false
}
"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

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): void;
function assert(value: any, message?: string | Error): asserts value;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,7 +19,7 @@ declare module "assert" {
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): void;
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. */
@ -28,9 +28,9 @@ declare module "assert" {
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 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(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: Function, message?: string | Error): void;
@ -38,7 +38,7 @@ declare module "assert" {
function doesNotThrow(block: Function, message?: string | Error): void;
function doesNotThrow(block: Function, error: RegExp | Function, message?: string | Error): void;
function ifError(value: any): void;
function ifError(value: any): asserts value is null | undefined;
function rejects(block: Function | Promise<any>, message?: string | Error): Promise<void>;
function rejects(block: Function | Promise<any>, error: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;

View File

@ -1,40 +1,20 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />
// 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.2/base.d.ts" />
// TypeScript 3.7-specific augmentations:
/// <reference path="assert.d.ts" />

View File

@ -1,94 +1,5 @@
// Type definitions for Node.js 10.17
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Zane Hannan AU <https://github.com/ZaneHannanAU>
// Jeremie Rodriguez <https://github.com/jeremiergz>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Minh Son Nguyen <https://github.com/nguymin4>
// ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// 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
// NOTE: These definitions support NodeJS and TypeScript 3.1.
// 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.1/index.d.ts - Definitions specific to TypeScript 3.1
// NOTE: Augmentations for TypeScript 3.1 and later should use individual files for overrides
// within the respective ~/ts3.1 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.1, so the older definitions will be found here.
// 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" />
// TypeScript 2.1-specific augmentations:
// Forward-declarations for needed types from es2015 and later (in case users are using `--lib es5`)
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
interface WeakSetConstructor { }
interface Set<T> {}
interface ReadonlySet<T> {}
interface IteratorResult<T> { }
interface Iterable<T> { }
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly iterator: symbol;
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace inspect {
const custom: symbol;
}
namespace promisify {
const custom: symbol;
}
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,14 +2,14 @@
"private": true,
"types": "index",
"typesVersions": {
">=3.7.0-0": {
"<=3.1": {
"*": [
"ts3.7/*"
"ts3.1/*"
]
},
">=3.2.0-0": {
"<=3.6": {
"*": [
"ts3.2/*"
"ts3.6/*"
]
}
}

View File

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): asserts value;
function assert(value: any, message?: string | Error): void;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,7 +19,7 @@ declare module "assert" {
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;
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. */
@ -28,9 +28,9 @@ declare module "assert" {
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 strictEqual(actual: any, expected: any, message?: string | Error): void;
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 deepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function throws(block: Function, message?: string | Error): void;
@ -38,7 +38,7 @@ declare module "assert" {
function doesNotThrow(block: Function, message?: string | Error): void;
function doesNotThrow(block: Function, error: RegExp | Function, message?: string | Error): void;
function ifError(value: any): asserts value is null | undefined;
function ifError(value: any): void;
function rejects(block: Function | Promise<any>, message?: string | Error): Promise<void>;
function rejects(block: Function | Promise<any>, error: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;

40
types/node/v10/ts3.1/base.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />

94
types/node/v10/ts3.1/index.d.ts vendored Normal file
View File

@ -0,0 +1,94 @@
// Type definitions for Node.js 10.17
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Zane Hannan AU <https://github.com/ZaneHannanAU>
// Jeremie Rodriguez <https://github.com/jeremiergz>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Minh Son Nguyen <https://github.com/nguymin4>
// ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// NOTE: These definitions support NodeJS and TypeScript 3.1.
// 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.1/index.d.ts - Definitions specific to TypeScript 3.1
// NOTE: Augmentations for TypeScript 3.1 and later should use individual files for overrides
// within the respective ~/ts3.1 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.1, so the older definitions will be found here.
// 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" />
// TypeScript 2.1-specific augmentations:
// Forward-declarations for needed types from es2015 and later (in case users are using `--lib es5`)
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
interface WeakSetConstructor { }
interface Set<T> {}
interface ReadonlySet<T> {}
interface IteratorResult<T> { }
interface Iterable<T> { }
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly iterator: symbol;
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace inspect {
const custom: symbol;
}
namespace promisify {
const custom: symbol;
}
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,20 +0,0 @@
// 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.2/base.d.ts" />
// TypeScript 3.7-specific augmentations:
/// <reference path="assert.d.ts" />

View File

@ -1,5 +0,0 @@
// 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

@ -1,59 +0,0 @@
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
}
{
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

@ -1,10 +0,0 @@
{
"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

@ -1,10 +1,10 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false,
"no-empty-interface": false,
"no-single-declare-module": false,
"strict-export-declare-modifiers": false,
"unified-signatures": false
}
"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

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): void;
function assert(value: any, message?: string | Error): asserts value;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,7 +19,7 @@ declare module "assert" {
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): void;
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. */
@ -28,9 +28,9 @@ declare module "assert" {
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 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(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;
@ -38,7 +38,7 @@ declare module "assert" {
function doesNotThrow(block: () => any, message?: string | Error): void;
function doesNotThrow(block: () => any, error: RegExp | Function, message?: string | Error): void;
function ifError(value: any): 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: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;

View File

@ -1,40 +1,20 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />
// 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.2/base.d.ts" />
// TypeScript 3.7-specific augmentations:
/// <reference path="assert.d.ts" />

View File

@ -1,103 +1,5 @@
// Type definitions for non-npm package Node.js 11.15
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Benjamin Toueg <https://github.com/btoueg>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// David Junger <https://github.com/touffy>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Zane Hannan AU <https://github.com/ZaneHannanAU>
// Jeremie Rodriguez <https://github.com/jeremiergz>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Ivan Sieder <https://github.com/ivansieder>
// Minh Son Nguyen <https://github.com/nguymin4>
// ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// 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
// 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/index.d.ts - Definitions specific to TypeScript 3.2
// NOTE: Augmentations for TypeScript 3.2 and later should use individual files for overrides
// within the respective ~/ts3.2 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.2, so the older definitions will be found here.
// 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" />
// TypeScript 2.1-specific augmentations:
// 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.
// if someone really needs these types the libs need to be added via --lib or in tsconfig.json
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
interface WeakSetConstructor { }
interface Set<T> {}
interface Map<K, V> {}
interface ReadonlySet<T> {}
interface IteratorResult<T> { }
interface Iterable<T> { }
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly iterator: symbol;
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
// even this is just a forward declaration some properties are added otherwise
// it would be allowed to pass anything to e.g. Buffer.from()
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace inspect {
const custom: symbol;
}
namespace promisify {
const custom: symbol;
}
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,14 +2,14 @@
"private": true,
"types": "index",
"typesVersions": {
">=3.7.0-0": {
"<=3.1": {
"*": [
"ts3.7/*"
"ts3.1/*"
]
},
">=3.2.0-0": {
"<=3.6": {
"*": [
"ts3.2/*"
"ts3.6/*"
]
}
}

View File

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): asserts value;
function assert(value: any, message?: string | Error): void;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,7 +19,7 @@ declare module "assert" {
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;
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. */
@ -28,9 +28,9 @@ declare module "assert" {
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 strictEqual(actual: any, expected: any, message?: string | Error): void;
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 deepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function throws(block: () => any, message?: string | Error): void;
@ -38,7 +38,7 @@ declare module "assert" {
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 ifError(value: any): void;
function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
function rejects(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;

40
types/node/v11/ts3.1/base.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />

103
types/node/v11/ts3.1/index.d.ts vendored Normal file
View File

@ -0,0 +1,103 @@
// Type definitions for non-npm package Node.js 11.15
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Benjamin Toueg <https://github.com/btoueg>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// David Junger <https://github.com/touffy>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Zane Hannan AU <https://github.com/ZaneHannanAU>
// Jeremie Rodriguez <https://github.com/jeremiergz>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Ivan Sieder <https://github.com/ivansieder>
// Minh Son Nguyen <https://github.com/nguymin4>
// ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// 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/index.d.ts - Definitions specific to TypeScript 3.2
// NOTE: Augmentations for TypeScript 3.2 and later should use individual files for overrides
// within the respective ~/ts3.2 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.2, so the older definitions will be found here.
// 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" />
// TypeScript 2.1-specific augmentations:
// 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.
// if someone really needs these types the libs need to be added via --lib or in tsconfig.json
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
interface WeakSetConstructor { }
interface Set<T> {}
interface Map<K, V> {}
interface ReadonlySet<T> {}
interface IteratorResult<T> { }
interface Iterable<T> { }
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly iterator: symbol;
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
// even this is just a forward declaration some properties are added otherwise
// it would be allowed to pass anything to e.g. Buffer.from()
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace inspect {
const custom: symbol;
}
namespace promisify {
const custom: symbol;
}
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,20 +0,0 @@
// 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.2/base.d.ts" />
// TypeScript 3.7-specific augmentations:
/// <reference path="assert.d.ts" />

View File

@ -1,5 +0,0 @@
// 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

@ -1,59 +0,0 @@
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

@ -1,10 +0,0 @@
{
"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

@ -1,10 +1,10 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false,
"no-empty-interface": false,
"no-single-declare-module": false,
"strict-export-declare-modifiers": false,
"unified-signatures": false
}
"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

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): void;
function assert(value: any, message?: string | Error): asserts value;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,7 +19,7 @@ declare module "assert" {
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): void;
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. */
@ -28,9 +28,9 @@ declare module "assert" {
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 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(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;
@ -38,7 +38,7 @@ declare module "assert" {
function doesNotThrow(block: () => any, message?: string | Error): void;
function doesNotThrow(block: () => any, error: RegExp | Function, message?: string | Error): void;
function ifError(value: any): 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: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;

View File

@ -1,40 +1,20 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />
// 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.4/base.d.ts" />
// TypeScript 3.7-specific augmentations:
/// <reference path="assert.d.ts" />

View File

@ -1,110 +1,5 @@
// Type definitions for non-npm package Node.js 12.12
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Benjamin Toueg <https://github.com/btoueg>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// David Junger <https://github.com/touffy>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Zane Hannan AU <https://github.com/ZaneHannanAU>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Marcin Kopacz <https://github.com/chyzwar>
// Trivikram Kamat <https://github.com/trivikr>
// Minh Son Nguyen <https://github.com/nguymin4>
// Junxiao Shi <https://github.com/yoursunny>
// Ilia Baryshnikov <https://github.com/qwelias>
// ExE Boss <https://github.com/ExE-Boss>
// Jason Kwok <https://github.com/JasonHK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// 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
// 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/index.d.ts - Definitions specific to TypeScript 3.2
// NOTE: Augmentations for TypeScript 3.2 and later should use individual files for overrides
// within the respective ~/ts3.2 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.2, so the older definitions will be found here.
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />
// We can't include globals.global.d.ts in globals.d.ts, as it'll cause duplication errors in TypeScript 3.4+
/// <reference path="globals.global.d.ts" />
// We can't include assert.d.ts in base.d.ts, as it'll cause duplication errors in TypeScript 3.7+
/// <reference path="assert.d.ts" />
// TypeScript 2.1-specific augmentations:
// 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.
// if someone really needs these types the libs need to be added via --lib or in tsconfig.json
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
interface WeakSetConstructor { }
interface Set<T> {}
interface Map<K, V> {}
interface ReadonlySet<T> {}
interface Iterable<T> { }
interface IteratorResult<T> { }
interface AsyncIterable<T> { }
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly iterator: symbol;
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
// even this is just a forward declaration some properties are added otherwise
// it would be allowed to pass anything to e.g. Buffer.from()
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace inspect {
const custom: symbol;
}
namespace promisify {
const custom: symbol;
}
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

View File

@ -1,898 +1,59 @@
import assert = require("assert");
import * as fs from "fs";
import * as url from "url";
import * as util from "util";
import * as http from "http";
import * as https from "https";
import * as console2 from "console";
import * as timers from "timers";
import * as dns from "dns";
import * as inspector from "inspector";
import * as trace_events from "trace_events";
import * as dgram from "dgram";
import Module = require("module");
import * as assert from 'assert';
////////////////////////////////////////////////////
/// Url tests : http://nodejs.org/api/url.html
////////////////////////////////////////////////////
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');
{
{
url.format(url.parse('http://www.example.com/xyz'));
url.format('http://www.example.com/xyz');
// https://google.com/search?q=you're%20a%20lizard%2C%20gary
url.format({
protocol: 'https',
host: "google.com",
pathname: 'search',
query: { q: "you're a lizard, gary" }
});
const myURL = new url.URL('https://a:b@你好你好?abc#foo');
url.format(myURL, { fragment: false, unicode: true, auth: false });
}
{
const helloUrl = url.parse('http://example.com/?hello=world', true);
let helloQuery = helloUrl.query['hello'];
assert.equal(helloUrl.query['hello'], 'world');
let strUrl = url.parse('http://example.com/?hello=world');
let queryStr: string = strUrl.query!;
strUrl = url.parse('http://example.com/?hello=world', false);
queryStr = strUrl.query!;
function getBoolean(): boolean { return false; }
const urlUrl = url.parse('http://example.com/?hello=world', getBoolean());
if (typeof(urlUrl.query) === 'string') {
queryStr = urlUrl.query;
} else if (urlUrl.query) {
helloQuery = urlUrl.query['hello'];
}
}
{
const ascii: string = url.domainToASCII('español.com');
const unicode: string = url.domainToUnicode('xn--espaol-zwa.com');
}
{
let myURL = new url.URL('https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.hash, '#bar');
assert.equal(myURL.host, 'example.org:81');
assert.equal(myURL.hostname, 'example.org');
assert.equal(myURL.href, 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.origin, 'https://example.org:81');
assert.equal(myURL.password, 'thepwd');
assert.equal(myURL.username, 'theuser');
assert.equal(myURL.pathname, '/foo/path');
assert.equal(myURL.port, "81");
assert.equal(myURL.protocol, "https:");
assert.equal(myURL.search, "?query=string");
assert.equal(myURL.toString(), 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert(myURL.searchParams instanceof url.URLSearchParams);
myURL.host = 'example.org:82';
myURL.hostname = 'example.com';
myURL.href = 'http://other.com';
myURL.hash = 'baz';
myURL.password = "otherpwd";
myURL.username = "otheruser";
myURL.pathname = "/otherPath";
myURL.port = "82";
myURL.protocol = "http";
myURL.search = "a=b";
assert.equal(myURL.href, 'http://otheruser:otherpwd@other.com:82/otherPath?a=b#baz');
myURL = new url.URL('/foo', 'https://example.org/');
assert.equal(myURL.href, 'https://example.org/foo');
assert.equal(myURL.toJSON(), myURL.href);
}
{
const searchParams = new url.URLSearchParams('abc=123');
assert.equal(searchParams.toString(), 'abc=123');
searchParams.forEach((value: string, name: string, me: url.URLSearchParams): void => {
assert.equal(name, 'abc');
assert.equal(value, '123');
assert.equal(me, searchParams);
});
assert.equal(searchParams.get('abc'), '123');
searchParams.append('abc', 'xyz');
assert.deepEqual(searchParams.getAll('abc'), ['123', 'xyz']);
const entries = searchParams.entries();
assert.deepEqual(entries.next(), { value: ["abc", "123"], done: false });
assert.deepEqual(entries.next(), { value: ["abc", "xyz"], done: false });
assert.deepEqual(entries.next(), { value: undefined, done: true });
const keys = searchParams.keys();
assert.deepEqual(keys.next(), { value: "abc", done: false });
assert.deepEqual(keys.next(), { value: "abc", done: false });
assert.deepEqual(keys.next(), { value: undefined, done: true });
const values = searchParams.values();
assert.deepEqual(values.next(), { value: "123", done: false });
assert.deepEqual(values.next(), { value: "xyz", done: false });
assert.deepEqual(values.next(), { value: undefined, done: true });
searchParams.set('abc', 'b');
assert.deepEqual(searchParams.getAll('abc'), ['b']);
searchParams.delete('a');
assert(!searchParams.has('a'));
assert.equal(searchParams.get('a'), null);
searchParams.sort();
}
{
const searchParams = new url.URLSearchParams({
user: 'abc',
query: ['first', 'second']
});
assert.equal(searchParams.toString(), 'user=abc&query=first%2Csecond');
assert.deepEqual(searchParams.getAll('query'), ['first,second']);
}
{
// Using an array
const params = new url.URLSearchParams([
['user', 'abc'],
['query', 'first'],
['query', 'second'],
// ts 2.1/2.* compatibility
// tslint:disable-next-line no-unnecessary-type-assertion
] as Array<[string, string]>);
assert.equal(params.toString(), 'user=abc&query=first&query=second');
}
{
let path: string = url.fileURLToPath('file://test');
path = url.fileURLToPath(new url.URL('file://test'));
}
{
const path: url.URL = url.pathToFileURL('file://test');
}
const a = null as any;
assert.ifError(a);
a; // $ExpectType null | undefined
}
//////////////////////////////////////////////////////
/// Https tests : http://nodejs.org/api/https.html ///
//////////////////////////////////////////////////////
{
let agent: https.Agent = new https.Agent({
keepAlive: true,
keepAliveMsecs: 10000,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
timeout: 15000
});
agent = https.globalAgent;
https.request({
agent: false
});
https.request({
agent
});
https.request({
agent: undefined
});
https.get('http://www.example.com/xyz');
https.request('http://www.example.com/xyz');
https.get('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.request('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.get(new url.URL('http://www.example.com/xyz'));
https.request(new url.URL('http://www.example.com/xyz'));
https.get(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
const opts: https.RequestOptions = {
path: '/some/path'
};
https.get(new url.URL('http://www.example.com'), opts);
https.request(new url.URL('http://www.example.com'), opts);
https.get(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.globalAgent.options.ca = [];
{
function reqListener(req: http.IncomingMessage, res: http.ServerResponse): void {}
class MyIncomingMessage extends http.IncomingMessage {
foo: number;
}
class MyServerResponse extends http.ServerResponse {
foo: string;
}
let server: https.Server;
server = new https.Server();
server = new https.Server(reqListener);
server = new https.Server({ IncomingMessage: MyIncomingMessage});
server = new https.Server({
IncomingMessage: MyIncomingMessage,
ServerResponse: MyServerResponse
}, reqListener);
server = https.createServer();
server = https.createServer(reqListener);
server = https.createServer({ IncomingMessage: MyIncomingMessage });
server = https.createServer({ ServerResponse: MyServerResponse }, reqListener);
const timeout: number = server.timeout;
const listening: boolean = server.listening;
const keepAliveTimeout: number = server.keepAliveTimeout;
const maxHeadersCount: number | null = server.maxHeadersCount;
const headersTimeout: number = server.headersTimeout;
server.setTimeout().setTimeout(1000).setTimeout(() => {}).setTimeout(100, () => {});
}
const a = true as boolean;
assert(a);
a; // $ExpectType true
}
/////////////////////////////////////////////////////
/// Timers tests : https://nodejs.org/api/timers.html
/////////////////////////////////////////////////////
{
{
const immediate = timers
.setImmediate(() => {
console.log('immediate');
})
.unref()
.ref();
const b: boolean = immediate.hasRef();
timers.clearImmediate(immediate);
}
{
const timeout = timers
.setInterval(() => {
console.log('interval');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearInterval(timeout);
}
{
const timeout = timers
.setTimeout(() => {
console.log('timeout');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearTimeout(timeout);
}
async function testPromisify() {
const setTimeout = util.promisify(timers.setTimeout);
let v: void = await setTimeout(100); // tslint:disable-line no-void-expression void-return
let s: string = await setTimeout(100, "");
const setImmediate = util.promisify(timers.setImmediate);
v = await setImmediate(); // tslint:disable-line no-void-expression
s = await setImmediate("");
}
// tslint:disable-next-line: no-null-undefined-union
const a = 13 as number | null | undefined;
assert(a);
a; // $ExpectType number
}
/////////////////////////////////////////////////////////
/// Errors Tests : https://nodejs.org/api/errors.html ///
/////////////////////////////////////////////////////////
{
{
Error.stackTraceLimit = Infinity;
}
{
const myObject = {};
Error.captureStackTrace(myObject);
}
{
const frames: NodeJS.CallSite[] = [];
Error.prepareStackTrace!(new Error(), frames);
}
{
const frame: NodeJS.CallSite = null!;
const frameThis: any = frame.getThis();
const typeName: string | null = frame.getTypeName();
const func: Function | undefined = frame.getFunction();
const funcName: string | null = frame.getFunctionName();
const meth: string | null = frame.getMethodName();
const fname: string | null = frame.getFileName();
const lineno: number | null = frame.getLineNumber();
const colno: number | null = frame.getColumnNumber();
const evalOrigin: string | undefined = frame.getEvalOrigin();
const isTop: boolean = frame.isToplevel();
const isEval: boolean = frame.isEval();
const isNative: boolean = frame.isNative();
const isConstr: boolean = frame.isConstructor();
}
const a = true as boolean;
assert.ok(a);
a; // $ExpectType true
}
///////////////////////////////////////////////////////////
/// Console Tests : https://nodejs.org/api/console.html ///
///////////////////////////////////////////////////////////
{
{
let _c: Console = console;
_c = console2;
}
{
const writeStream = fs.createWriteStream('./index.d.ts');
let consoleInstance: Console = new console.Console(writeStream);
consoleInstance = new console.Console(writeStream, writeStream);
consoleInstance = new console.Console(writeStream, writeStream, true);
consoleInstance = new console.Console({
stdout: writeStream,
stderr: writeStream,
colorMode: 'auto',
ignoreErrors: true
});
consoleInstance = new console.Console({
stdout: writeStream,
colorMode: false
});
consoleInstance = new console.Console({
stdout: writeStream
});
}
{
console.assert('value');
console.assert('value', 'message');
console.assert('value', 'message', 'foo', 'bar');
console.clear();
console.count();
console.count('label');
console.countReset();
console.countReset('label');
console.debug();
console.debug('message');
console.debug('message', 'foo', 'bar');
console.dir('obj');
console.dir('obj', { depth: 1 });
console.error();
console.error('message');
console.error('message', 'foo', 'bar');
console.group();
console.group('label');
console.group('label1', 'label2');
console.groupCollapsed();
console.groupEnd();
console.info();
console.info('message');
console.info('message', 'foo', 'bar');
console.log();
console.log('message');
console.log('message', 'foo', 'bar');
console.table({ foo: 'bar' });
console.table([{ foo: 'bar' }]);
console.table([{ foo: 'bar' }], ['foo']);
console.time();
console.time('label');
console.timeEnd();
console.timeEnd('label');
console.timeLog();
console.timeLog('label');
console.timeLog('label', 'foo', 'bar');
console.trace();
console.trace('message');
console.trace('message', 'foo', 'bar');
console.warn();
console.warn('message');
console.warn('message', 'foo', 'bar');
// --- Inspector mode only ---
console.markTimeline();
console.markTimeline('label');
console.profile();
console.profile('label');
console.profileEnd();
console.profileEnd('label');
console.timeStamp();
console.timeStamp('label');
console.timeline();
console.timeline('label');
console.timelineEnd();
console.timelineEnd('label');
}
// tslint:disable-next-line: no-null-undefined-union
const a = 13 as number | null | undefined;
assert.ok(a);
a; // $ExpectType number
}
///////////////////////////////////////////////////
/// DNS Tests : https://nodejs.org/api/dns.html ///
///////////////////////////////////////////////////
{
dns.lookup("nodejs.org", (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 4, (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 6, (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", {}, (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup(
"nodejs.org",
{
family: 4,
hints: dns.ADDRCONFIG | dns.V4MAPPED,
all: false
},
(err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
}
);
dns.lookup("nodejs.org", { all: true }, (err, addresses) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: dns.LookupAddress[] = addresses;
});
dns.lookup("nodejs.org", { all: true, verbatim: true }, (err, addresses) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: dns.LookupAddress[] = addresses;
});
function trueOrFalse(): boolean {
return Math.random() > 0.5 ? true : false;
}
dns.lookup("nodejs.org", { all: trueOrFalse() }, (err, addresses, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _addresses: string | dns.LookupAddress[] = addresses;
const _family: number | undefined = family;
});
dns.lookupService("127.0.0.1", 0, (err, hostname, service) => {
const _err: NodeJS.ErrnoException | null = err;
const _hostname: string = hostname;
const _service: string = service;
});
dns.resolve("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve("nodejs.org", "A", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve("nodejs.org", "AAAA", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve("nodejs.org", "ANY", (err, addresses) => {
const _addresses: dns.AnyRecord[] = addresses;
});
dns.resolve("nodejs.org", "MX", (err, addresses) => {
const _addresses: dns.MxRecord[] = addresses;
});
dns.resolve4("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve4("nodejs.org", { ttl: true }, (err, addresses) => {
const _addresses: dns.RecordWithTtl[] = addresses;
});
{
const ttl = false;
dns.resolve4("nodejs.org", { ttl }, (err, addresses) => {
const _addresses: string[] | dns.RecordWithTtl[] = addresses;
});
}
dns.resolve6("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve6("nodejs.org", { ttl: true }, (err, addresses) => {
const _addresses: dns.RecordWithTtl[] = addresses;
});
{
const ttl = false;
dns.resolve6("nodejs.org", { ttl }, (err, addresses) => {
const _addresses: string[] | dns.RecordWithTtl[] = addresses;
});
}
{
const resolver = new dns.Resolver();
resolver.setServers(["4.4.4.4"]);
resolver.resolve("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
resolver.cancel();
}
const a = 'test' as any;
assert.strictEqual(a, 'test');
a; // $ExpectType string
}
/*****************************************************************************
* *
* The following tests are the modules not mentioned in document but existed *
* *
*****************************************************************************/
///////////////////////////////////////////////////////////
/// Constants Tests ///
///////////////////////////////////////////////////////////
import * as constants from 'constants';
{
let str: string;
let num: number;
num = constants.SIGHUP;
num = constants.SIGINT;
num = constants.SIGQUIT;
num = constants.SIGILL;
num = constants.SIGTRAP;
num = constants.SIGABRT;
num = constants.SIGIOT;
num = constants.SIGBUS;
num = constants.SIGFPE;
num = constants.SIGKILL;
num = constants.SIGUSR1;
num = constants.SIGSEGV;
num = constants.SIGUSR2;
num = constants.SIGPIPE;
num = constants.SIGALRM;
num = constants.SIGTERM;
num = constants.SIGCHLD;
num = constants.SIGSTKFLT;
num = constants.SIGCONT;
num = constants.SIGSTOP;
num = constants.SIGTSTP;
num = constants.SIGTTIN;
num = constants.SIGTTOU;
num = constants.SIGURG;
num = constants.SIGXCPU;
num = constants.SIGXFSZ;
num = constants.SIGVTALRM;
num = constants.SIGPROF;
num = constants.SIGWINCH;
num = constants.SIGIO;
num = constants.SIGPOLL;
num = constants.SIGPWR;
num = constants.SIGSYS;
num = constants.SIGUNUSED;
num = constants.O_RDONLY;
num = constants.O_WRONLY;
num = constants.O_RDWR;
num = constants.S_IFMT;
num = constants.S_IFREG;
num = constants.S_IFDIR;
num = constants.S_IFCHR;
num = constants.S_IFBLK;
num = constants.S_IFIFO;
num = constants.S_IFLNK;
num = constants.S_IFSOCK;
num = constants.O_CREAT;
num = constants.O_EXCL;
num = constants.O_NOCTTY;
num = constants.O_TRUNC;
num = constants.O_APPEND;
num = constants.O_DIRECTORY;
num = constants.O_NOATIME;
num = constants.O_NOFOLLOW;
num = constants.O_SYNC;
num = constants.O_DSYNC;
num = constants.O_DIRECT;
num = constants.O_NONBLOCK;
num = constants.S_IRWXU;
num = constants.S_IRUSR;
num = constants.S_IWUSR;
num = constants.S_IXUSR;
num = constants.S_IRWXG;
num = constants.S_IRGRP;
num = constants.S_IWGRP;
num = constants.S_IXGRP;
num = constants.S_IRWXO;
num = constants.S_IROTH;
num = constants.S_IWOTH;
num = constants.S_IXOTH;
num = constants.F_OK;
num = constants.R_OK;
num = constants.W_OK;
num = constants.X_OK;
num = constants.SSL_OP_ALL;
num = constants.SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION;
num = constants.SSL_OP_CIPHER_SERVER_PREFERENCE;
num = constants.SSL_OP_CISCO_ANYCONNECT;
num = constants.SSL_OP_COOKIE_EXCHANGE;
num = constants.SSL_OP_CRYPTOPRO_TLSEXT_BUG;
num = constants.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
num = constants.SSL_OP_EPHEMERAL_RSA;
num = constants.SSL_OP_LEGACY_SERVER_CONNECT;
num = constants.SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER;
num = constants.SSL_OP_MICROSOFT_SESS_ID_BUG;
num = constants.SSL_OP_MSIE_SSLV2_RSA_PADDING;
num = constants.SSL_OP_NETSCAPE_CA_DN_BUG;
num = constants.SSL_OP_NETSCAPE_CHALLENGE_BUG;
num = constants.SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG;
num = constants.SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG;
num = constants.SSL_OP_NO_COMPRESSION;
num = constants.SSL_OP_NO_QUERY_MTU;
num = constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION;
num = constants.SSL_OP_NO_SSLv2;
num = constants.SSL_OP_NO_SSLv3;
num = constants.SSL_OP_NO_TICKET;
num = constants.SSL_OP_NO_TLSv1;
num = constants.SSL_OP_NO_TLSv1_1;
num = constants.SSL_OP_NO_TLSv1_2;
num = constants.SSL_OP_PKCS1_CHECK_1;
num = constants.SSL_OP_PKCS1_CHECK_2;
num = constants.SSL_OP_SINGLE_DH_USE;
num = constants.SSL_OP_SINGLE_ECDH_USE;
num = constants.SSL_OP_SSLEAY_080_CLIENT_DH_BUG;
num = constants.SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG;
num = constants.SSL_OP_TLS_BLOCK_PADDING_BUG;
num = constants.SSL_OP_TLS_D5_BUG;
num = constants.SSL_OP_TLS_ROLLBACK_BUG;
num = constants.ENGINE_METHOD_RSA;
num = constants.ENGINE_METHOD_DSA;
num = constants.ENGINE_METHOD_DH;
num = constants.ENGINE_METHOD_RAND;
num = constants.ENGINE_METHOD_ECDH;
num = constants.ENGINE_METHOD_ECDSA;
num = constants.ENGINE_METHOD_CIPHERS;
num = constants.ENGINE_METHOD_DIGESTS;
num = constants.ENGINE_METHOD_STORE;
num = constants.ENGINE_METHOD_PKEY_METHS;
num = constants.ENGINE_METHOD_PKEY_ASN1_METHS;
num = constants.ENGINE_METHOD_ALL;
num = constants.ENGINE_METHOD_NONE;
num = constants.DH_CHECK_P_NOT_SAFE_PRIME;
num = constants.DH_CHECK_P_NOT_PRIME;
num = constants.DH_UNABLE_TO_CHECK_GENERATOR;
num = constants.DH_NOT_SUITABLE_GENERATOR;
num = constants.ALPN_ENABLED;
num = constants.RSA_PKCS1_PADDING;
num = constants.RSA_SSLV23_PADDING;
num = constants.RSA_NO_PADDING;
num = constants.RSA_PKCS1_OAEP_PADDING;
num = constants.RSA_X931_PADDING;
num = constants.RSA_PKCS1_PSS_PADDING;
num = constants.POINT_CONVERSION_COMPRESSED;
num = constants.POINT_CONVERSION_UNCOMPRESSED;
num = constants.POINT_CONVERSION_HYBRID;
str = constants.defaultCoreCipherList;
str = constants.defaultCipherList;
}
///////////////////////////////////////////////////////////
/// Inspector Tests ///
///////////////////////////////////////////////////////////
{
{
const b: inspector.Console.ConsoleMessage = {source: 'test', text: 'test', level: 'error' };
inspector.open();
inspector.open(0);
inspector.open(0, 'localhost');
inspector.open(0, 'localhost', true);
inspector.close();
const inspectorUrl: string | undefined = inspector.url();
const session = new inspector.Session();
session.connect();
session.disconnect();
// Unknown post method
session.post('A.b', { key: 'value' }, (err, params) => {});
// TODO: parameters are implicitly 'any' and need type annotation
session.post('A.b', (err: Error | null, params?: {}) => {});
session.post('A.b');
// Known post method
const parameter: inspector.Runtime.EvaluateParameterType = { expression: '2 + 2' };
session.post('Runtime.evaluate', parameter,
(err: Error | null, params: inspector.Runtime.EvaluateReturnType) => {});
session.post('Runtime.evaluate', (err: Error, params: inspector.Runtime.EvaluateReturnType) => {
const exceptionDetails: inspector.Runtime.ExceptionDetails = params.exceptionDetails!;
const resultClassName: string = params.result.className!;
});
session.post('Runtime.evaluate');
// General event
session.on('inspectorNotification', message => {
message; // $ExpectType InspectorNotification<{}>
});
// Known events
session.on('Debugger.paused', (message: inspector.InspectorNotification<inspector.Debugger.PausedEventDataType>) => {
const method: string = message.method;
const pauseReason: string = message.params.reason;
});
session.on('Debugger.resumed', () => {});
// Node Inspector events
session.on('NodeTracing.dataCollected', (message: inspector.InspectorNotification<inspector.NodeTracing.DataCollectedEventDataType>) => {
const value: Array<{}> = message.params.value;
});
}
}
///////////////////////////////////////////////////////////
/// Trace Events Tests ///
///////////////////////////////////////////////////////////
{
const enabledCategories: string | undefined = trace_events.getEnabledCategories();
const tracing: trace_events.Tracing = trace_events.createTracing({ categories: ['node', 'v8'] });
const categories: string = tracing.categories;
const enabled: boolean = tracing.enabled;
tracing.enable();
tracing.disable();
}
////////////////////////////////////////////////////
/// module tests : http://nodejs.org/api/modules.html
////////////////////////////////////////////////////
import moduleModule = require('module');
{
require.extensions[".ts"] = () => "";
Module.runMain();
const s: string = Module.wrap("some code");
const m1: Module = new Module("moduleId");
const m2: Module = new Module.Module("moduleId");
const b: string[] = Module.builtinModules;
let paths: string[] = module.paths;
const path: string = module.path;
paths = m1.paths;
const customRequire1 = moduleModule.createRequireFromPath('./test');
const customRequire2 = moduleModule.createRequire('./test');
customRequire1('test');
customRequire2('test');
const resolved1: string = customRequire1.resolve('test');
const resolved2: string = customRequire2.resolve('test');
const paths1: string[] | null = customRequire1.resolve.paths('test');
const paths2: string[] | null = customRequire2.resolve.paths('test');
const cachedModule1: Module = customRequire1.cache['/path/to/module.js'];
const cachedModule2: Module = customRequire2.cache['/path/to/module.js'];
const main1: Module | undefined = customRequire1.main;
const main2: Module | undefined = customRequire2.main;
}
/////////////////////////////////////////////////////////
/// stream tests : https://nodejs.org/api/stream.html ///
/////////////////////////////////////////////////////////
import stream = require('stream');
import tty = require('tty');
{
const writeStream = fs.createWriteStream('./index.d.ts');
const _wom = writeStream.writableObjectMode; // $ExpectType boolean
const readStream = fs.createReadStream('./index.d.ts');
const _rom = readStream.readableObjectMode; // $ExpectType boolean
const x: stream.Readable = process.stdin;
const stdin: tty.ReadStream = process.stdin;
const stdout: tty.WriteStream = process.stdout;
const stderr: tty.WriteStream = process.stderr;
}
/////////////////////////////////////////////////////////
/// dgram tests : https://nodejs.org/api/dgram.html ///
/////////////////////////////////////////////////////////
{
let sock: dgram.Socket = dgram.createSocket("udp4");
sock = dgram.createSocket({ type: "udp4" });
sock = dgram.createSocket({
type: "udp4",
reuseAddr: true,
ipv6Only: false,
recvBufferSize: 4096,
sendBufferSize: 4096,
lookup: dns.lookup,
});
sock = dgram.createSocket("udp6", (msg, rinfo) => {
msg; // $ExpectType Buffer
rinfo; // $ExpectType RemoteInfo
});
sock.addMembership("233.252.0.0");
sock.addMembership("233.252.0.0", "192.0.2.1");
sock.address().address; // $ExpectType string
sock.address().family; // $ExpectType string
sock.address().port; // $ExpectType number
sock.bind();
sock.bind(() => undefined);
sock.bind(8000);
sock.bind(8000, () => undefined);
sock.bind(8000, "192.0.2.1");
sock.bind(8000, "192.0.2.1", () => undefined);
sock.bind({}, () => undefined);
sock.bind({ port: 8000, address: "192.0.2.1", exclusive: true });
sock.bind({ fd: 7, exclusive: true });
sock.close();
sock.close(() => undefined);
sock.connect(8000);
sock.connect(8000, "192.0.2.1");
sock.connect(8000, () => undefined);
sock.connect(8000, "192.0.2.1", () => undefined);
sock.disconnect();
sock.dropMembership("233.252.0.0");
sock.dropMembership("233.252.0.0", "192.0.2.1");
sock.getRecvBufferSize(); // $ExpectType number
sock.getSendBufferSize(); // $ExpectType number
sock = sock.ref();
sock.remoteAddress().address; // $ExpectType string
sock.remoteAddress().family; // $ExpectType string
sock.remoteAddress().port; // $ExpectType number
sock.send("datagram");
sock.send(new Uint8Array(256), 8000, (err) => {
err; // $ExpectType Error | null
});
sock.send(Buffer.alloc(256), 8000, "192.0.2.1");
sock.send(new Uint8Array(256), 128, 64);
sock.send("datagram", 128, 64, (err) => undefined);
sock.send(new Uint8Array(256), 128, 64, 8000);
sock.send(new Uint8Array(256), 128, 64, 8000, (err) => undefined);
sock.send(Buffer.alloc(256), 128, 64, 8000, "192.0.2.1");
sock.send("datagram", 128, 64, 8000, "192.0.2.1", (err) => undefined);
sock.setBroadcast(true);
sock.setMulticastInterface("192.0.2.1");
sock.setMulticastLoopback(false);
sock.setMulticastTTL(128);
sock.setRecvBufferSize(4096);
sock.setSendBufferSize(4096);
sock.setTTL(128);
sock = sock.unref();
sock.on("close", () => undefined);
sock.on("connect", () => undefined);
sock.on("error", (exception) => {
exception; // $ExpectType Error
});
sock.on("listening", () => undefined);
sock.on("message", (msg, rinfo) => {
msg; // $ExpectType Buffer
rinfo.address; // $ExpectType string
rinfo.family; // $ExpectType "IPv4" | "IPv6"
rinfo.port; // $ExpectType number
rinfo.size; // $ExpectType number
});
}
////////////////////////////////////////////////////
/// Node.js ESNEXT Support
////////////////////////////////////////////////////
{
const s = 'foo';
const s1: string = s.trimLeft();
const s2: string = s.trimRight();
const a = { b: 2 } as any;
assert.deepStrictEqual(a, { b: 2 });
a; // $ExpectType { b: number; }
}

View File

@ -2,19 +2,19 @@
"private": true,
"types": "index",
"typesVersions": {
">=3.7.0-0": {
"<=3.1": {
"*": [
"ts3.7/*"
"ts3.1/*"
]
},
">=3.4.0-0": {
"<=3.3": {
"*": [
"ts3.4/*"
"ts3.3/*"
]
},
">=3.2.0-0": {
"<=3.6": {
"*": [
"ts3.2/*"
"ts3.6/*"
]
}
}

View File

@ -1,5 +1,5 @@
declare module "assert" {
function assert(value: any, message?: string | Error): asserts value;
function assert(value: any, message?: string | Error): void;
namespace assert {
class AssertionError implements Error {
name: string;
@ -19,7 +19,7 @@ declare module "assert" {
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;
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. */
@ -28,9 +28,9 @@ declare module "assert" {
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 strictEqual(actual: any, expected: any, message?: string | Error): void;
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 deepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function throws(block: () => any, message?: string | Error): void;
@ -38,7 +38,7 @@ declare module "assert" {
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 ifError(value: any): void;
function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
function rejects(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;

40
types/node/v12/ts3.1/base.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
// base definitions for all NodeJS modules that are not specific to any version of TypeScript
/// <reference path="globals.d.ts" />
/// <reference path="async_hooks.d.ts" />
/// <reference path="buffer.d.ts" />
/// <reference path="child_process.d.ts" />
/// <reference path="cluster.d.ts" />
/// <reference path="console.d.ts" />
/// <reference path="constants.d.ts" />
/// <reference path="crypto.d.ts" />
/// <reference path="dgram.d.ts" />
/// <reference path="dns.d.ts" />
/// <reference path="domain.d.ts" />
/// <reference path="events.d.ts" />
/// <reference path="fs.d.ts" />
/// <reference path="http.d.ts" />
/// <reference path="http2.d.ts" />
/// <reference path="https.d.ts" />
/// <reference path="inspector.d.ts" />
/// <reference path="module.d.ts" />
/// <reference path="net.d.ts" />
/// <reference path="os.d.ts" />
/// <reference path="path.d.ts" />
/// <reference path="perf_hooks.d.ts" />
/// <reference path="process.d.ts" />
/// <reference path="punycode.d.ts" />
/// <reference path="querystring.d.ts" />
/// <reference path="readline.d.ts" />
/// <reference path="repl.d.ts" />
/// <reference path="stream.d.ts" />
/// <reference path="string_decoder.d.ts" />
/// <reference path="timers.d.ts" />
/// <reference path="tls.d.ts" />
/// <reference path="trace_events.d.ts" />
/// <reference path="tty.d.ts" />
/// <reference path="url.d.ts" />
/// <reference path="util.d.ts" />
/// <reference path="v8.d.ts" />
/// <reference path="vm.d.ts" />
/// <reference path="worker_threads.d.ts" />
/// <reference path="zlib.d.ts" />

110
types/node/v12/ts3.1/index.d.ts vendored Normal file
View File

@ -0,0 +1,110 @@
// Type definitions for non-npm package Node.js 12.12
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
// Alberto Schiabel <https://github.com/jkomyno>
// Alexander T. <https://github.com/a-tarasyuk>
// Alvis HT Tang <https://github.com/alvis>
// Andrew Makarov <https://github.com/r3nya>
// Benjamin Toueg <https://github.com/btoueg>
// Bruno Scheufler <https://github.com/brunoscheufler>
// Chigozirim C. <https://github.com/smac89>
// David Junger <https://github.com/touffy>
// Deividas Bakanas <https://github.com/DeividasBakanas>
// Eugene Y. Q. Shen <https://github.com/eyqs>
// Flarna <https://github.com/Flarna>
// Hannes Magnusson <https://github.com/Hannes-Magnusson-CK>
// Hoàng Văn Khải <https://github.com/KSXGitHub>
// Huw <https://github.com/hoo29>
// Kelvin Jin <https://github.com/kjin>
// Klaus Meinhardt <https://github.com/ajafff>
// Lishude <https://github.com/islishude>
// Mariusz Wiktorczyk <https://github.com/mwiktorczyk>
// Mohsen Azimi <https://github.com/mohsen1>
// Nicolas Even <https://github.com/n-e>
// Nikita Galkin <https://github.com/galkin>
// Parambir Singh <https://github.com/parambirs>
// Sebastian Silbermann <https://github.com/eps1lon>
// Simon Schick <https://github.com/SimonSchick>
// Thomas den Hollander <https://github.com/ThomasdenH>
// Wilco Bakker <https://github.com/WilcoBakker>
// wwwy3y3 <https://github.com/wwwy3y3>
// Zane Hannan AU <https://github.com/ZaneHannanAU>
// Samuel Ainsworth <https://github.com/samuela>
// Kyle Uehlein <https://github.com/kuehlein>
// Jordi Oliveras Rovira <https://github.com/j-oliveras>
// Thanik Bhongbhibhat <https://github.com/bhongy>
// Marcin Kopacz <https://github.com/chyzwar>
// Trivikram Kamat <https://github.com/trivikr>
// Minh Son Nguyen <https://github.com/nguymin4>
// Junxiao Shi <https://github.com/yoursunny>
// Ilia Baryshnikov <https://github.com/qwelias>
// ExE Boss <https://github.com/ExE-Boss>
// Jason Kwok <https://github.com/JasonHK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// 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/index.d.ts - Definitions specific to TypeScript 3.2
// NOTE: Augmentations for TypeScript 3.2 and later should use individual files for overrides
// within the respective ~/ts3.2 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.2, so the older definitions will be found here.
// Base definitions for all NodeJS modules that are not specific to any version of TypeScript:
/// <reference path="base.d.ts" />
// We can't include globals.global.d.ts in globals.d.ts, as it'll cause duplication errors in TypeScript 3.4+
/// <reference path="globals.global.d.ts" />
// We can't include assert.d.ts in base.d.ts, as it'll cause duplication errors in TypeScript 3.7+
/// <reference path="assert.d.ts" />
// TypeScript 2.1-specific augmentations:
// 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.
// if someone really needs these types the libs need to be added via --lib or in tsconfig.json
interface MapConstructor { }
interface WeakMapConstructor { }
interface SetConstructor { }
interface WeakSetConstructor { }
interface Set<T> {}
interface Map<K, V> {}
interface ReadonlySet<T> {}
interface Iterable<T> { }
interface IteratorResult<T> { }
interface AsyncIterable<T> { }
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface IterableIterator<T> { }
interface AsyncIterableIterator<T> {}
interface SymbolConstructor {
readonly iterator: symbol;
readonly asyncIterator: symbol;
}
declare var Symbol: SymbolConstructor;
// even this is just a forward declaration some properties are added otherwise
// it would be allowed to pass anything to e.g. Buffer.from()
interface SharedArrayBuffer {
readonly byteLength: number;
slice(begin?: number, end?: number): SharedArrayBuffer;
}
declare module "util" {
namespace inspect {
const custom: symbol;
}
namespace promisify {
const custom: symbol;
}
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}

View File

@ -0,0 +1,898 @@
import assert = require("assert");
import * as fs from "fs";
import * as url from "url";
import * as util from "util";
import * as http from "http";
import * as https from "https";
import * as console2 from "console";
import * as timers from "timers";
import * as dns from "dns";
import * as inspector from "inspector";
import * as trace_events from "trace_events";
import * as dgram from "dgram";
import Module = require("module");
////////////////////////////////////////////////////
/// Url tests : http://nodejs.org/api/url.html
////////////////////////////////////////////////////
{
{
url.format(url.parse('http://www.example.com/xyz'));
url.format('http://www.example.com/xyz');
// https://google.com/search?q=you're%20a%20lizard%2C%20gary
url.format({
protocol: 'https',
host: "google.com",
pathname: 'search',
query: { q: "you're a lizard, gary" }
});
const myURL = new url.URL('https://a:b@你好你好?abc#foo');
url.format(myURL, { fragment: false, unicode: true, auth: false });
}
{
const helloUrl = url.parse('http://example.com/?hello=world', true);
let helloQuery = helloUrl.query['hello'];
assert.equal(helloUrl.query['hello'], 'world');
let strUrl = url.parse('http://example.com/?hello=world');
let queryStr: string = strUrl.query!;
strUrl = url.parse('http://example.com/?hello=world', false);
queryStr = strUrl.query!;
function getBoolean(): boolean { return false; }
const urlUrl = url.parse('http://example.com/?hello=world', getBoolean());
if (typeof(urlUrl.query) === 'string') {
queryStr = urlUrl.query;
} else if (urlUrl.query) {
helloQuery = urlUrl.query['hello'];
}
}
{
const ascii: string = url.domainToASCII('español.com');
const unicode: string = url.domainToUnicode('xn--espaol-zwa.com');
}
{
let myURL = new url.URL('https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.hash, '#bar');
assert.equal(myURL.host, 'example.org:81');
assert.equal(myURL.hostname, 'example.org');
assert.equal(myURL.href, 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.origin, 'https://example.org:81');
assert.equal(myURL.password, 'thepwd');
assert.equal(myURL.username, 'theuser');
assert.equal(myURL.pathname, '/foo/path');
assert.equal(myURL.port, "81");
assert.equal(myURL.protocol, "https:");
assert.equal(myURL.search, "?query=string");
assert.equal(myURL.toString(), 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert(myURL.searchParams instanceof url.URLSearchParams);
myURL.host = 'example.org:82';
myURL.hostname = 'example.com';
myURL.href = 'http://other.com';
myURL.hash = 'baz';
myURL.password = "otherpwd";
myURL.username = "otheruser";
myURL.pathname = "/otherPath";
myURL.port = "82";
myURL.protocol = "http";
myURL.search = "a=b";
assert.equal(myURL.href, 'http://otheruser:otherpwd@other.com:82/otherPath?a=b#baz');
myURL = new url.URL('/foo', 'https://example.org/');
assert.equal(myURL.href, 'https://example.org/foo');
assert.equal(myURL.toJSON(), myURL.href);
}
{
const searchParams = new url.URLSearchParams('abc=123');
assert.equal(searchParams.toString(), 'abc=123');
searchParams.forEach((value: string, name: string, me: url.URLSearchParams): void => {
assert.equal(name, 'abc');
assert.equal(value, '123');
assert.equal(me, searchParams);
});
assert.equal(searchParams.get('abc'), '123');
searchParams.append('abc', 'xyz');
assert.deepEqual(searchParams.getAll('abc'), ['123', 'xyz']);
const entries = searchParams.entries();
assert.deepEqual(entries.next(), { value: ["abc", "123"], done: false });
assert.deepEqual(entries.next(), { value: ["abc", "xyz"], done: false });
assert.deepEqual(entries.next(), { value: undefined, done: true });
const keys = searchParams.keys();
assert.deepEqual(keys.next(), { value: "abc", done: false });
assert.deepEqual(keys.next(), { value: "abc", done: false });
assert.deepEqual(keys.next(), { value: undefined, done: true });
const values = searchParams.values();
assert.deepEqual(values.next(), { value: "123", done: false });
assert.deepEqual(values.next(), { value: "xyz", done: false });
assert.deepEqual(values.next(), { value: undefined, done: true });
searchParams.set('abc', 'b');
assert.deepEqual(searchParams.getAll('abc'), ['b']);
searchParams.delete('a');
assert(!searchParams.has('a'));
assert.equal(searchParams.get('a'), null);
searchParams.sort();
}
{
const searchParams = new url.URLSearchParams({
user: 'abc',
query: ['first', 'second']
});
assert.equal(searchParams.toString(), 'user=abc&query=first%2Csecond');
assert.deepEqual(searchParams.getAll('query'), ['first,second']);
}
{
// Using an array
const params = new url.URLSearchParams([
['user', 'abc'],
['query', 'first'],
['query', 'second'],
// ts 2.1/2.* compatibility
// tslint:disable-next-line no-unnecessary-type-assertion
] as Array<[string, string]>);
assert.equal(params.toString(), 'user=abc&query=first&query=second');
}
{
let path: string = url.fileURLToPath('file://test');
path = url.fileURLToPath(new url.URL('file://test'));
}
{
const path: url.URL = url.pathToFileURL('file://test');
}
}
//////////////////////////////////////////////////////
/// Https tests : http://nodejs.org/api/https.html ///
//////////////////////////////////////////////////////
{
let agent: https.Agent = new https.Agent({
keepAlive: true,
keepAliveMsecs: 10000,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
timeout: 15000
});
agent = https.globalAgent;
https.request({
agent: false
});
https.request({
agent
});
https.request({
agent: undefined
});
https.get('http://www.example.com/xyz');
https.request('http://www.example.com/xyz');
https.get('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.request('http://www.example.com/xyz', (res: http.IncomingMessage): void => {});
https.get(new url.URL('http://www.example.com/xyz'));
https.request(new url.URL('http://www.example.com/xyz'));
https.get(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), (res: http.IncomingMessage): void => {});
const opts: https.RequestOptions = {
path: '/some/path'
};
https.get(new url.URL('http://www.example.com'), opts);
https.request(new url.URL('http://www.example.com'), opts);
https.get(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.request(new url.URL('http://www.example.com/xyz'), opts, (res: http.IncomingMessage): void => {});
https.globalAgent.options.ca = [];
{
function reqListener(req: http.IncomingMessage, res: http.ServerResponse): void {}
class MyIncomingMessage extends http.IncomingMessage {
foo: number;
}
class MyServerResponse extends http.ServerResponse {
foo: string;
}
let server: https.Server;
server = new https.Server();
server = new https.Server(reqListener);
server = new https.Server({ IncomingMessage: MyIncomingMessage});
server = new https.Server({
IncomingMessage: MyIncomingMessage,
ServerResponse: MyServerResponse
}, reqListener);
server = https.createServer();
server = https.createServer(reqListener);
server = https.createServer({ IncomingMessage: MyIncomingMessage });
server = https.createServer({ ServerResponse: MyServerResponse }, reqListener);
const timeout: number = server.timeout;
const listening: boolean = server.listening;
const keepAliveTimeout: number = server.keepAliveTimeout;
const maxHeadersCount: number | null = server.maxHeadersCount;
const headersTimeout: number = server.headersTimeout;
server.setTimeout().setTimeout(1000).setTimeout(() => {}).setTimeout(100, () => {});
}
}
/////////////////////////////////////////////////////
/// Timers tests : https://nodejs.org/api/timers.html
/////////////////////////////////////////////////////
{
{
const immediate = timers
.setImmediate(() => {
console.log('immediate');
})
.unref()
.ref();
const b: boolean = immediate.hasRef();
timers.clearImmediate(immediate);
}
{
const timeout = timers
.setInterval(() => {
console.log('interval');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearInterval(timeout);
}
{
const timeout = timers
.setTimeout(() => {
console.log('timeout');
}, 20)
.unref()
.ref()
.refresh();
const b: boolean = timeout.hasRef();
timers.clearTimeout(timeout);
}
async function testPromisify() {
const setTimeout = util.promisify(timers.setTimeout);
let v: void = await setTimeout(100); // tslint:disable-line no-void-expression void-return
let s: string = await setTimeout(100, "");
const setImmediate = util.promisify(timers.setImmediate);
v = await setImmediate(); // tslint:disable-line no-void-expression
s = await setImmediate("");
}
}
/////////////////////////////////////////////////////////
/// Errors Tests : https://nodejs.org/api/errors.html ///
/////////////////////////////////////////////////////////
{
{
Error.stackTraceLimit = Infinity;
}
{
const myObject = {};
Error.captureStackTrace(myObject);
}
{
const frames: NodeJS.CallSite[] = [];
Error.prepareStackTrace!(new Error(), frames);
}
{
const frame: NodeJS.CallSite = null!;
const frameThis: any = frame.getThis();
const typeName: string | null = frame.getTypeName();
const func: Function | undefined = frame.getFunction();
const funcName: string | null = frame.getFunctionName();
const meth: string | null = frame.getMethodName();
const fname: string | null = frame.getFileName();
const lineno: number | null = frame.getLineNumber();
const colno: number | null = frame.getColumnNumber();
const evalOrigin: string | undefined = frame.getEvalOrigin();
const isTop: boolean = frame.isToplevel();
const isEval: boolean = frame.isEval();
const isNative: boolean = frame.isNative();
const isConstr: boolean = frame.isConstructor();
}
}
///////////////////////////////////////////////////////////
/// Console Tests : https://nodejs.org/api/console.html ///
///////////////////////////////////////////////////////////
{
{
let _c: Console = console;
_c = console2;
}
{
const writeStream = fs.createWriteStream('./index.d.ts');
let consoleInstance: Console = new console.Console(writeStream);
consoleInstance = new console.Console(writeStream, writeStream);
consoleInstance = new console.Console(writeStream, writeStream, true);
consoleInstance = new console.Console({
stdout: writeStream,
stderr: writeStream,
colorMode: 'auto',
ignoreErrors: true
});
consoleInstance = new console.Console({
stdout: writeStream,
colorMode: false
});
consoleInstance = new console.Console({
stdout: writeStream
});
}
{
console.assert('value');
console.assert('value', 'message');
console.assert('value', 'message', 'foo', 'bar');
console.clear();
console.count();
console.count('label');
console.countReset();
console.countReset('label');
console.debug();
console.debug('message');
console.debug('message', 'foo', 'bar');
console.dir('obj');
console.dir('obj', { depth: 1 });
console.error();
console.error('message');
console.error('message', 'foo', 'bar');
console.group();
console.group('label');
console.group('label1', 'label2');
console.groupCollapsed();
console.groupEnd();
console.info();
console.info('message');
console.info('message', 'foo', 'bar');
console.log();
console.log('message');
console.log('message', 'foo', 'bar');
console.table({ foo: 'bar' });
console.table([{ foo: 'bar' }]);
console.table([{ foo: 'bar' }], ['foo']);
console.time();
console.time('label');
console.timeEnd();
console.timeEnd('label');
console.timeLog();
console.timeLog('label');
console.timeLog('label', 'foo', 'bar');
console.trace();
console.trace('message');
console.trace('message', 'foo', 'bar');
console.warn();
console.warn('message');
console.warn('message', 'foo', 'bar');
// --- Inspector mode only ---
console.markTimeline();
console.markTimeline('label');
console.profile();
console.profile('label');
console.profileEnd();
console.profileEnd('label');
console.timeStamp();
console.timeStamp('label');
console.timeline();
console.timeline('label');
console.timelineEnd();
console.timelineEnd('label');
}
}
///////////////////////////////////////////////////
/// DNS Tests : https://nodejs.org/api/dns.html ///
///////////////////////////////////////////////////
{
dns.lookup("nodejs.org", (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 4, (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 6, (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", {}, (err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup(
"nodejs.org",
{
family: 4,
hints: dns.ADDRCONFIG | dns.V4MAPPED,
all: false
},
(err, address, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: string = address;
const _family: number = family;
}
);
dns.lookup("nodejs.org", { all: true }, (err, addresses) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: dns.LookupAddress[] = addresses;
});
dns.lookup("nodejs.org", { all: true, verbatim: true }, (err, addresses) => {
const _err: NodeJS.ErrnoException | null = err;
const _address: dns.LookupAddress[] = addresses;
});
function trueOrFalse(): boolean {
return Math.random() > 0.5 ? true : false;
}
dns.lookup("nodejs.org", { all: trueOrFalse() }, (err, addresses, family) => {
const _err: NodeJS.ErrnoException | null = err;
const _addresses: string | dns.LookupAddress[] = addresses;
const _family: number | undefined = family;
});
dns.lookupService("127.0.0.1", 0, (err, hostname, service) => {
const _err: NodeJS.ErrnoException | null = err;
const _hostname: string = hostname;
const _service: string = service;
});
dns.resolve("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve("nodejs.org", "A", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve("nodejs.org", "AAAA", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve("nodejs.org", "ANY", (err, addresses) => {
const _addresses: dns.AnyRecord[] = addresses;
});
dns.resolve("nodejs.org", "MX", (err, addresses) => {
const _addresses: dns.MxRecord[] = addresses;
});
dns.resolve4("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve4("nodejs.org", { ttl: true }, (err, addresses) => {
const _addresses: dns.RecordWithTtl[] = addresses;
});
{
const ttl = false;
dns.resolve4("nodejs.org", { ttl }, (err, addresses) => {
const _addresses: string[] | dns.RecordWithTtl[] = addresses;
});
}
dns.resolve6("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
dns.resolve6("nodejs.org", { ttl: true }, (err, addresses) => {
const _addresses: dns.RecordWithTtl[] = addresses;
});
{
const ttl = false;
dns.resolve6("nodejs.org", { ttl }, (err, addresses) => {
const _addresses: string[] | dns.RecordWithTtl[] = addresses;
});
}
{
const resolver = new dns.Resolver();
resolver.setServers(["4.4.4.4"]);
resolver.resolve("nodejs.org", (err, addresses) => {
const _addresses: string[] = addresses;
});
resolver.cancel();
}
}
/*****************************************************************************
* *
* The following tests are the modules not mentioned in document but existed *
* *
*****************************************************************************/
///////////////////////////////////////////////////////////
/// Constants Tests ///
///////////////////////////////////////////////////////////
import * as constants from 'constants';
{
let str: string;
let num: number;
num = constants.SIGHUP;
num = constants.SIGINT;
num = constants.SIGQUIT;
num = constants.SIGILL;
num = constants.SIGTRAP;
num = constants.SIGABRT;
num = constants.SIGIOT;
num = constants.SIGBUS;
num = constants.SIGFPE;
num = constants.SIGKILL;
num = constants.SIGUSR1;
num = constants.SIGSEGV;
num = constants.SIGUSR2;
num = constants.SIGPIPE;
num = constants.SIGALRM;
num = constants.SIGTERM;
num = constants.SIGCHLD;
num = constants.SIGSTKFLT;
num = constants.SIGCONT;
num = constants.SIGSTOP;
num = constants.SIGTSTP;
num = constants.SIGTTIN;
num = constants.SIGTTOU;
num = constants.SIGURG;
num = constants.SIGXCPU;
num = constants.SIGXFSZ;
num = constants.SIGVTALRM;
num = constants.SIGPROF;
num = constants.SIGWINCH;
num = constants.SIGIO;
num = constants.SIGPOLL;
num = constants.SIGPWR;
num = constants.SIGSYS;
num = constants.SIGUNUSED;
num = constants.O_RDONLY;
num = constants.O_WRONLY;
num = constants.O_RDWR;
num = constants.S_IFMT;
num = constants.S_IFREG;
num = constants.S_IFDIR;
num = constants.S_IFCHR;
num = constants.S_IFBLK;
num = constants.S_IFIFO;
num = constants.S_IFLNK;
num = constants.S_IFSOCK;
num = constants.O_CREAT;
num = constants.O_EXCL;
num = constants.O_NOCTTY;
num = constants.O_TRUNC;
num = constants.O_APPEND;
num = constants.O_DIRECTORY;
num = constants.O_NOATIME;
num = constants.O_NOFOLLOW;
num = constants.O_SYNC;
num = constants.O_DSYNC;
num = constants.O_DIRECT;
num = constants.O_NONBLOCK;
num = constants.S_IRWXU;
num = constants.S_IRUSR;
num = constants.S_IWUSR;
num = constants.S_IXUSR;
num = constants.S_IRWXG;
num = constants.S_IRGRP;
num = constants.S_IWGRP;
num = constants.S_IXGRP;
num = constants.S_IRWXO;
num = constants.S_IROTH;
num = constants.S_IWOTH;
num = constants.S_IXOTH;
num = constants.F_OK;
num = constants.R_OK;
num = constants.W_OK;
num = constants.X_OK;
num = constants.SSL_OP_ALL;
num = constants.SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION;
num = constants.SSL_OP_CIPHER_SERVER_PREFERENCE;
num = constants.SSL_OP_CISCO_ANYCONNECT;
num = constants.SSL_OP_COOKIE_EXCHANGE;
num = constants.SSL_OP_CRYPTOPRO_TLSEXT_BUG;
num = constants.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
num = constants.SSL_OP_EPHEMERAL_RSA;
num = constants.SSL_OP_LEGACY_SERVER_CONNECT;
num = constants.SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER;
num = constants.SSL_OP_MICROSOFT_SESS_ID_BUG;
num = constants.SSL_OP_MSIE_SSLV2_RSA_PADDING;
num = constants.SSL_OP_NETSCAPE_CA_DN_BUG;
num = constants.SSL_OP_NETSCAPE_CHALLENGE_BUG;
num = constants.SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG;
num = constants.SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG;
num = constants.SSL_OP_NO_COMPRESSION;
num = constants.SSL_OP_NO_QUERY_MTU;
num = constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION;
num = constants.SSL_OP_NO_SSLv2;
num = constants.SSL_OP_NO_SSLv3;
num = constants.SSL_OP_NO_TICKET;
num = constants.SSL_OP_NO_TLSv1;
num = constants.SSL_OP_NO_TLSv1_1;
num = constants.SSL_OP_NO_TLSv1_2;
num = constants.SSL_OP_PKCS1_CHECK_1;
num = constants.SSL_OP_PKCS1_CHECK_2;
num = constants.SSL_OP_SINGLE_DH_USE;
num = constants.SSL_OP_SINGLE_ECDH_USE;
num = constants.SSL_OP_SSLEAY_080_CLIENT_DH_BUG;
num = constants.SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG;
num = constants.SSL_OP_TLS_BLOCK_PADDING_BUG;
num = constants.SSL_OP_TLS_D5_BUG;
num = constants.SSL_OP_TLS_ROLLBACK_BUG;
num = constants.ENGINE_METHOD_RSA;
num = constants.ENGINE_METHOD_DSA;
num = constants.ENGINE_METHOD_DH;
num = constants.ENGINE_METHOD_RAND;
num = constants.ENGINE_METHOD_ECDH;
num = constants.ENGINE_METHOD_ECDSA;
num = constants.ENGINE_METHOD_CIPHERS;
num = constants.ENGINE_METHOD_DIGESTS;
num = constants.ENGINE_METHOD_STORE;
num = constants.ENGINE_METHOD_PKEY_METHS;
num = constants.ENGINE_METHOD_PKEY_ASN1_METHS;
num = constants.ENGINE_METHOD_ALL;
num = constants.ENGINE_METHOD_NONE;
num = constants.DH_CHECK_P_NOT_SAFE_PRIME;
num = constants.DH_CHECK_P_NOT_PRIME;
num = constants.DH_UNABLE_TO_CHECK_GENERATOR;
num = constants.DH_NOT_SUITABLE_GENERATOR;
num = constants.ALPN_ENABLED;
num = constants.RSA_PKCS1_PADDING;
num = constants.RSA_SSLV23_PADDING;
num = constants.RSA_NO_PADDING;
num = constants.RSA_PKCS1_OAEP_PADDING;
num = constants.RSA_X931_PADDING;
num = constants.RSA_PKCS1_PSS_PADDING;
num = constants.POINT_CONVERSION_COMPRESSED;
num = constants.POINT_CONVERSION_UNCOMPRESSED;
num = constants.POINT_CONVERSION_HYBRID;
str = constants.defaultCoreCipherList;
str = constants.defaultCipherList;
}
///////////////////////////////////////////////////////////
/// Inspector Tests ///
///////////////////////////////////////////////////////////
{
{
const b: inspector.Console.ConsoleMessage = {source: 'test', text: 'test', level: 'error' };
inspector.open();
inspector.open(0);
inspector.open(0, 'localhost');
inspector.open(0, 'localhost', true);
inspector.close();
const inspectorUrl: string | undefined = inspector.url();
const session = new inspector.Session();
session.connect();
session.disconnect();
// Unknown post method
session.post('A.b', { key: 'value' }, (err, params) => {});
// TODO: parameters are implicitly 'any' and need type annotation
session.post('A.b', (err: Error | null, params?: {}) => {});
session.post('A.b');
// Known post method
const parameter: inspector.Runtime.EvaluateParameterType = { expression: '2 + 2' };
session.post('Runtime.evaluate', parameter,
(err: Error | null, params: inspector.Runtime.EvaluateReturnType) => {});
session.post('Runtime.evaluate', (err: Error, params: inspector.Runtime.EvaluateReturnType) => {
const exceptionDetails: inspector.Runtime.ExceptionDetails = params.exceptionDetails!;
const resultClassName: string = params.result.className!;
});
session.post('Runtime.evaluate');
// General event
session.on('inspectorNotification', message => {
message; // $ExpectType InspectorNotification<{}>
});
// Known events
session.on('Debugger.paused', (message: inspector.InspectorNotification<inspector.Debugger.PausedEventDataType>) => {
const method: string = message.method;
const pauseReason: string = message.params.reason;
});
session.on('Debugger.resumed', () => {});
// Node Inspector events
session.on('NodeTracing.dataCollected', (message: inspector.InspectorNotification<inspector.NodeTracing.DataCollectedEventDataType>) => {
const value: Array<{}> = message.params.value;
});
}
}
///////////////////////////////////////////////////////////
/// Trace Events Tests ///
///////////////////////////////////////////////////////////
{
const enabledCategories: string | undefined = trace_events.getEnabledCategories();
const tracing: trace_events.Tracing = trace_events.createTracing({ categories: ['node', 'v8'] });
const categories: string = tracing.categories;
const enabled: boolean = tracing.enabled;
tracing.enable();
tracing.disable();
}
////////////////////////////////////////////////////
/// module tests : http://nodejs.org/api/modules.html
////////////////////////////////////////////////////
import moduleModule = require('module');
{
require.extensions[".ts"] = () => "";
Module.runMain();
const s: string = Module.wrap("some code");
const m1: Module = new Module("moduleId");
const m2: Module = new Module.Module("moduleId");
const b: string[] = Module.builtinModules;
let paths: string[] = module.paths;
const path: string = module.path;
paths = m1.paths;
const customRequire1 = moduleModule.createRequireFromPath('./test');
const customRequire2 = moduleModule.createRequire('./test');
customRequire1('test');
customRequire2('test');
const resolved1: string = customRequire1.resolve('test');
const resolved2: string = customRequire2.resolve('test');
const paths1: string[] | null = customRequire1.resolve.paths('test');
const paths2: string[] | null = customRequire2.resolve.paths('test');
const cachedModule1: Module = customRequire1.cache['/path/to/module.js'];
const cachedModule2: Module = customRequire2.cache['/path/to/module.js'];
const main1: Module | undefined = customRequire1.main;
const main2: Module | undefined = customRequire2.main;
}
/////////////////////////////////////////////////////////
/// stream tests : https://nodejs.org/api/stream.html ///
/////////////////////////////////////////////////////////
import stream = require('stream');
import tty = require('tty');
{
const writeStream = fs.createWriteStream('./index.d.ts');
const _wom = writeStream.writableObjectMode; // $ExpectType boolean
const readStream = fs.createReadStream('./index.d.ts');
const _rom = readStream.readableObjectMode; // $ExpectType boolean
const x: stream.Readable = process.stdin;
const stdin: tty.ReadStream = process.stdin;
const stdout: tty.WriteStream = process.stdout;
const stderr: tty.WriteStream = process.stderr;
}
/////////////////////////////////////////////////////////
/// dgram tests : https://nodejs.org/api/dgram.html ///
/////////////////////////////////////////////////////////
{
let sock: dgram.Socket = dgram.createSocket("udp4");
sock = dgram.createSocket({ type: "udp4" });
sock = dgram.createSocket({
type: "udp4",
reuseAddr: true,
ipv6Only: false,
recvBufferSize: 4096,
sendBufferSize: 4096,
lookup: dns.lookup,
});
sock = dgram.createSocket("udp6", (msg, rinfo) => {
msg; // $ExpectType Buffer
rinfo; // $ExpectType RemoteInfo
});
sock.addMembership("233.252.0.0");
sock.addMembership("233.252.0.0", "192.0.2.1");
sock.address().address; // $ExpectType string
sock.address().family; // $ExpectType string
sock.address().port; // $ExpectType number
sock.bind();
sock.bind(() => undefined);
sock.bind(8000);
sock.bind(8000, () => undefined);
sock.bind(8000, "192.0.2.1");
sock.bind(8000, "192.0.2.1", () => undefined);
sock.bind({}, () => undefined);
sock.bind({ port: 8000, address: "192.0.2.1", exclusive: true });
sock.bind({ fd: 7, exclusive: true });
sock.close();
sock.close(() => undefined);
sock.connect(8000);
sock.connect(8000, "192.0.2.1");
sock.connect(8000, () => undefined);
sock.connect(8000, "192.0.2.1", () => undefined);
sock.disconnect();
sock.dropMembership("233.252.0.0");
sock.dropMembership("233.252.0.0", "192.0.2.1");
sock.getRecvBufferSize(); // $ExpectType number
sock.getSendBufferSize(); // $ExpectType number
sock = sock.ref();
sock.remoteAddress().address; // $ExpectType string
sock.remoteAddress().family; // $ExpectType string
sock.remoteAddress().port; // $ExpectType number
sock.send("datagram");
sock.send(new Uint8Array(256), 8000, (err) => {
err; // $ExpectType Error | null
});
sock.send(Buffer.alloc(256), 8000, "192.0.2.1");
sock.send(new Uint8Array(256), 128, 64);
sock.send("datagram", 128, 64, (err) => undefined);
sock.send(new Uint8Array(256), 128, 64, 8000);
sock.send(new Uint8Array(256), 128, 64, 8000, (err) => undefined);
sock.send(Buffer.alloc(256), 128, 64, 8000, "192.0.2.1");
sock.send("datagram", 128, 64, 8000, "192.0.2.1", (err) => undefined);
sock.setBroadcast(true);
sock.setMulticastInterface("192.0.2.1");
sock.setMulticastLoopback(false);
sock.setMulticastTTL(128);
sock.setRecvBufferSize(4096);
sock.setSendBufferSize(4096);
sock.setTTL(128);
sock = sock.unref();
sock.on("close", () => undefined);
sock.on("connect", () => undefined);
sock.on("error", (exception) => {
exception; // $ExpectType Error
});
sock.on("listening", () => undefined);
sock.on("message", (msg, rinfo) => {
msg; // $ExpectType Buffer
rinfo.address; // $ExpectType string
rinfo.family; // $ExpectType "IPv4" | "IPv6"
rinfo.port; // $ExpectType number
rinfo.size; // $ExpectType number
});
}
////////////////////////////////////////////////////
/// Node.js ESNEXT Support
////////////////////////////////////////////////////
{
const s = 'foo';
const s1: string = s.trimLeft();
const s2: string = s.trimRight();
}

View File

@ -0,0 +1,9 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false,
"no-empty-interface": false,
"no-single-declare-module": false,
"unified-signatures": false
}
}

Some files were not shown because too many files have changed in this diff Show More