Skip to content

Commit

Permalink
Fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Aug 20, 2021
1 parent 5960e1d commit 06fd8fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions index.d.ts
Expand Up @@ -99,10 +99,10 @@ export default class CacheableLookup {
/**
* @see https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback
*/
lookup(hostname: string, family: IPFamily, callback: (error: NodeJS.ErrnoException, address: string, family: IPFamily) => void): void;
lookup(hostname: string, callback: (error: NodeJS.ErrnoException, address: string, family: IPFamily) => void): void;
lookup(hostname: string, options: LookupOptions & {all: true}, callback: (error: NodeJS.ErrnoException, result: ReadonlyArray<EntryObject>) => void): void;
lookup(hostname: string, options: LookupOptions, callback: (error: NodeJS.ErrnoException, address: string, family: IPFamily) => void): void;
lookup(hostname: string, family: IPFamily, callback: (error: NodeJS.ErrnoException | null, address: string, family: IPFamily) => void): void;
lookup(hostname: string, callback: (error: NodeJS.ErrnoException | null, address: string, family: IPFamily) => void): void;
lookup(hostname: string, options: LookupOptions & {all: true}, callback: (error: NodeJS.ErrnoException | null, result: ReadonlyArray<EntryObject>) => void): void;
lookup(hostname: string, options: LookupOptions, callback: (error: NodeJS.ErrnoException | null, address: string, family: IPFamily) => void): void;
/**
* The asynchronous version of `dns.lookup(…)`.
*/
Expand Down
9 changes: 6 additions & 3 deletions index.test-d.ts
Expand Up @@ -37,22 +37,25 @@ import CacheableLookup, {EntryObject} from '.';
expectType<ReadonlyArray<EntryObject>>(await cacheable.lookupAsync('localhost', {all: true}));

cacheable.lookup('localhost', 6, (error, address, family) => {
expectType<NodeJS.ErrnoException>(error);
expectType<NodeJS.ErrnoException | null>(error);
expectType<string>(address);
expectType<4 | 6>(family);
});

cacheable.lookup('localhost', {all: false}, (error, address, family) => {
expectType<NodeJS.ErrnoException>(error);
expectType<NodeJS.ErrnoException | null>(error);
expectType<string>(address);
expectType<4 | 6>(family);
});

cacheable.lookup('localhost', {all: true}, (error, results) => {
expectType<NodeJS.ErrnoException>(error);
expectType<NodeJS.ErrnoException | null>(error);
expectType<ReadonlyArray<EntryObject>>(results);
});

// @types/node has invalid typings :(
// expectType<typeof cacheable.lookup>(lookup);

expectType<ReadonlyArray<EntryObject>>(await cacheable.query('localhost'));
expectType<ReadonlyArray<EntryObject>>(await cacheable.queryAndCache('localhost'));

Expand Down

0 comments on commit 06fd8fc

Please sign in to comment.