@types/node: fix dns.lookup() definitions (#15900)

* @types/node: fix dns.lookup() definitions

* fix optional family argument
This commit is contained in:
ikokostya
2017-05-03 22:09:15 +03:00
committed by Mohamed Hegazy
parent d1a979d719
commit 90cd78deeb
6 changed files with 249 additions and 6 deletions

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

@@ -1891,8 +1891,35 @@ declare module "dns" {
priority: number
}
export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) => void): string;
export function lookup(domain: string, callback: (err: Error, address: string, family: number) => void): string;
// Supported getaddrinfo flags.
export const ADDRCONFIG: number;
export const V4MAPPED: number;
export interface LookupOptions {
family?: number;
hints?: number;
all?: boolean;
}
export interface LookupOneOptions extends LookupOptions {
all?: false;
}
export interface LookupAllOptions extends LookupOptions {
all: true;
}
export interface LookupAddress {
address: string;
family: number;
}
export function lookup(domain: string, family: number, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function lookup(domain: string, options: LookupOneOptions, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function lookup(domain: string, options: LookupAllOptions, callback: (err: NodeJS.ErrnoException, addresses: LookupAddress[]) => void): void;
export function lookup(domain: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException, address: string | LookupAddress[], family: number) => void): void;
export function lookup(domain: string, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) => void): string[];
export function resolve(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
export function resolve4(domain: string, callback: (err: Error, addresses: string[]) => void): string[];

View File

@@ -25,6 +25,7 @@ import * as stream from "stream";
import * as timers from "timers";
import * as repl from "repl";
import * as v8 from "v8";
import * as dns from "dns";
// Specifically test buffer module regression.
import {Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer} from "buffer";
@@ -2127,6 +2128,59 @@ namespace repl_tests {
}
}
///////////////////////////////////////////////////
/// DNS Tests : https://nodejs.org/api/dns.html ///
///////////////////////////////////////////////////
namespace dns_tests {
dns.lookup("nodejs.org", (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 4, (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 6, (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", {}, (err, address, family) => {
const _err: NodeJS.ErrnoException = 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 = err;
const _address: string = address;
const _family: number = family;
}
);
dns.lookup("nodejs.org", {all: true}, (err, addresses) => {
const _err: NodeJS.ErrnoException = 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 = err;
const _addresses: string | dns.LookupAddress[] = addresses;
const _family: number | undefined = family;
});
}
/*****************************************************************************
* *
* The following tests are the modules not mentioned in document but existed *

View File

@@ -1242,8 +1242,35 @@ declare module "url" {
}
declare module "dns" {
export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string;
export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string;
// Supported getaddrinfo flags.
export const ADDRCONFIG: number;
export const V4MAPPED: number;
export interface LookupOptions {
family?: number;
hints?: number;
all?: boolean;
}
export interface LookupOneOptions extends LookupOptions {
all?: false;
}
export interface LookupAllOptions extends LookupOptions {
all: true;
}
export interface LookupAddress {
address: string;
family: number;
}
export function lookup(domain: string, family: number, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function lookup(domain: string, options: LookupOneOptions, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function lookup(domain: string, options: LookupAllOptions, callback: (err: NodeJS.ErrnoException, addresses: LookupAddress[]) => void): void;
export function lookup(domain: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException, address: string | LookupAddress[], family: number) => void): void;
export function lookup(domain: string, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[];
export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];

View File

@@ -19,6 +19,7 @@ import * as cluster from "cluster";
import * as os from "os";
import * as vm from "vm";
import * as string_decoder from "string_decoder";
import * as dns from "dns";
// Specifically test buffer module regression.
import {Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer} from "buffer";
@@ -968,3 +969,56 @@ namespace net_tests {
net.createServer().listen(0).close().address();
}
}
///////////////////////////////////////////////////
/// DNS Tests : https://nodejs.org/api/dns.html ///
///////////////////////////////////////////////////
namespace dns_tests {
dns.lookup("nodejs.org", (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 4, (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 6, (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", {}, (err, address, family) => {
const _err: NodeJS.ErrnoException = 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 = err;
const _address: string = address;
const _family: number = family;
}
);
dns.lookup("nodejs.org", {all: true}, (err, addresses) => {
const _err: NodeJS.ErrnoException = 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 = err;
const _addresses: string | dns.LookupAddress[] = addresses;
const _family: number | undefined = family;
});
}

View File

@@ -1812,8 +1812,35 @@ declare module "dns" {
priority: number
}
export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) => void): string;
export function lookup(domain: string, callback: (err: Error, address: string, family: number) => void): string;
// Supported getaddrinfo flags.
export const ADDRCONFIG: number;
export const V4MAPPED: number;
export interface LookupOptions {
family?: number;
hints?: number;
all?: boolean;
}
export interface LookupOneOptions extends LookupOptions {
all?: false;
}
export interface LookupAllOptions extends LookupOptions {
all: true;
}
export interface LookupAddress {
address: string;
family: number;
}
export function lookup(domain: string, family: number, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function lookup(domain: string, options: LookupOneOptions, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function lookup(domain: string, options: LookupAllOptions, callback: (err: NodeJS.ErrnoException, addresses: LookupAddress[]) => void): void;
export function lookup(domain: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException, address: string | LookupAddress[], family: number) => void): void;
export function lookup(domain: string, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) => void): string[];
export function resolve(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
export function resolve4(domain: string, callback: (err: Error, addresses: string[]) => void): string[];

View File

@@ -24,6 +24,7 @@ import * as string_decoder from "string_decoder";
import * as stream from "stream";
import * as timers from "timers";
import * as repl from "repl";
import * as dns from "dns";
// Specifically test buffer module regression.
import {Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer} from "buffer";
@@ -2039,6 +2040,59 @@ namespace repl_tests {
}
}
///////////////////////////////////////////////////
/// DNS Tests : https://nodejs.org/api/dns.html ///
///////////////////////////////////////////////////
namespace dns_tests {
dns.lookup("nodejs.org", (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 4, (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", 6, (err, address, family) => {
const _err: NodeJS.ErrnoException = err;
const _address: string = address;
const _family: number = family;
});
dns.lookup("nodejs.org", {}, (err, address, family) => {
const _err: NodeJS.ErrnoException = 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 = err;
const _address: string = address;
const _family: number = family;
}
);
dns.lookup("nodejs.org", {all: true}, (err, addresses) => {
const _err: NodeJS.ErrnoException = 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 = err;
const _addresses: string | dns.LookupAddress[] = addresses;
const _family: number | undefined = family;
});
}
/*****************************************************************************
* *
* The following tests are the modules not mentioned in document but existed *