Skip to content

Commit 481b7b1

Browse files
committed
address typescript type comment
1 parent bb16669 commit 481b7b1

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/connection_string.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,24 @@ const LB_REPLICA_SET_ERROR = 'loadBalanced option not supported with a replicaSe
4141
const LB_DIRECT_CONNECTION_ERROR =
4242
'loadBalanced option not supported when directConnection is provided';
4343

44-
function retryDNSTimeoutFor(rrtype: 'SRV'): (a: string) => Promise<dns.SrvRecord[]>;
45-
function retryDNSTimeoutFor(rrtype: 'TXT'): (a: string) => Promise<string[][]>;
46-
function retryDNSTimeoutFor(
47-
rrtype: 'SRV' | 'TXT'
48-
): (a: string) => Promise<dns.SrvRecord[] | string[][]> {
44+
// connect the rrtype to the expected result
45+
interface DNSLookupMap {
46+
SRV: dns.SrvRecord[];
47+
TXT: string[][];
48+
}
49+
function retryDNSTimeoutFor<T extends keyof DNSLookupMap>(
50+
rrtype: T
51+
): (lookupAddress: string) => Promise<DNSLookupMap[T]> {
4952
return async function dnsReqRetryTimeout(lookupAddress: string) {
53+
const resolve = () => dns.promises.resolve(lookupAddress, rrtype) as Promise<DNSLookupMap[T]>;
54+
5055
try {
51-
return (await dns.promises.resolve(lookupAddress, rrtype)) as dns.SrvRecord[] | string[][];
56+
return await resolve();
5257
} catch (firstDNSError) {
53-
if (firstDNSError.code === dns.TIMEOUT) {
54-
return (await dns.promises.resolve(lookupAddress, rrtype)) as dns.SrvRecord[] | string[][];
55-
} else {
56-
throw firstDNSError;
58+
if (firstDNSError.code === 'ETIMEOUT') {
59+
return await resolve();
5760
}
61+
throw firstDNSError;
5862
}
5963
};
6064
}

0 commit comments

Comments
 (0)