Skip to content

Commit d48dea1

Browse files
committed
improve some typescript errors
1 parent aac8949 commit d48dea1

File tree

8 files changed

+80
-681
lines changed

8 files changed

+80
-681
lines changed

src/node/dns.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://opensource.org/licenses/Apache-2.0
44
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
55

6+
import type nodejsDns from 'node:dns';
67
import * as errorCodes from 'node-internal:internal_dns_constants';
78
import * as dns from 'node-internal:internal_dns';
89
import { callbackify } from 'node-internal:internal_utils';
@@ -23,16 +24,16 @@ export const resolveSoa = callbackify(dns.resolveSoa.bind(dns));
2324
export const resolveNaptr = callbackify(dns.resolveNaptr.bind(dns));
2425
export const resolve4 = callbackify(dns.resolve4.bind(dns));
2526
export const resolve6 = callbackify(dns.resolve6.bind(dns));
26-
export const getServers = callbackify(dns.getServers.bind(dns));
27-
export const setServers = callbackify(dns.setServers.bind(dns));
27+
export const getServers = dns.getServers.bind(dns);
28+
export const setServers = dns.setServers.bind(dns);
2829
export const getDefaultResultOrder = dns.getDefaultResultOrder.bind(dns);
2930
export const setDefaultResultOrder = dns.setDefaultResultOrder.bind(dns);
3031
export const lookup = dns.lookup.bind(dns);
3132
export const lookupService = callbackify(dns.lookupService.bind(this));
3233
export const resolve = callbackify(dns.resolve.bind(this));
3334
export const resolveAny = callbackify(dns.resolveAny.bind(this));
3435

35-
export class Resolver {
36+
export class Resolver implements nodejsDns.Resolver {
3637
cancel(): void {
3738
// TODO(soon): Implement this.
3839
throw new Error('Not implemented');
@@ -43,58 +44,71 @@ export class Resolver {
4344
throw new Error('Not implemented');
4445
}
4546

46-
getServers(...args: Parameters<typeof getServers>): void {
47-
getServers(...args);
47+
getServers(...args: Parameters<typeof getServers>): string[] {
48+
return getServers(...args);
4849
}
4950

51+
// @ts-expect-error TS2416 Type mismatch.
5052
resolve(...args: Parameters<typeof resolve>): void {
5153
resolve(...args);
5254
}
5355

56+
// @ts-expect-error TS2416 Type mismatch.
5457
resolve4(...args: Parameters<typeof resolve4>): void {
5558
resolve4(...args);
5659
}
5760

61+
// @ts-expect-error TS2416 Type mismatch.
5862
resolve6(...args: Parameters<typeof resolve6>): void {
5963
resolve6(...args);
6064
}
6165

66+
// @ts-expect-error TS2416 Type mismatch.
6267
resolveAny(...args: Parameters<typeof resolveAny>): void {
6368
resolveAny(...args);
6469
}
6570

71+
// @ts-expect-error TS2416 Type mismatch.
6672
resolveCaa(...args: Parameters<typeof resolveCaa>): void {
6773
resolveCaa(...args);
6874
}
6975

76+
// @ts-expect-error TS2416 Type mismatch.
7077
resolveCname(...args: Parameters<typeof resolveCname>): void {
7178
resolveCname(...args);
7279
}
7380

81+
// @ts-expect-error TS2416 Type mismatch.
7482
resolveMx(...args: Parameters<typeof resolveMx>): void {
7583
resolveMx(...args);
7684
}
7785

86+
// @ts-expect-error TS2416 Type mismatch.
7887
resolveNaptr(...args: Parameters<typeof resolveNaptr>): void {
7988
resolveNaptr(...args);
8089
}
8190

91+
// @ts-expect-error TS2416 Type mismatch.
8292
resolveNs(...args: Parameters<typeof resolveNs>): void {
8393
resolveNs(...args);
8494
}
8595

96+
// @ts-expect-error TS2416 Type mismatch.
8697
resolvePtr(...args: Parameters<typeof resolvePtr>): void {
8798
resolvePtr(...args);
8899
}
89100

101+
// @ts-expect-error TS2416 Type mismatch.
90102
resolveSoa(...args: Parameters<typeof resolveSoa>): void {
91103
resolveSoa(...args);
92104
}
93105

106+
// @ts-expect-error TS2416 Type mismatch.
94107
resolveSrv(...args: Parameters<typeof resolveSrv>): void {
95108
resolveSrv(...args);
96109
}
97110

111+
// @ts-expect-error TS2416 Type mismatch.
98112
resolveTxt(...args: Parameters<typeof resolveTxt>): void {
99113
resolveTxt(...args);
100114
}

src/node/internal/internal_dns.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://opensource.org/licenses/Apache-2.0
44
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
55

6+
/* eslint-disable @typescript-eslint/no-deprecated */
67
import {
78
sendDnsRequest,
89
validateAnswer,
@@ -37,6 +38,7 @@ import {
3738
} from 'node-internal:validators';
3839
import * as errorCodes from 'node-internal:internal_dns_constants';
3940
import { isIP } from 'node-internal:internal_net';
41+
import type dns from 'node:dns';
4042

4143
type DnsOrder = 'verbatim' | 'ipv4first' | 'ipv6first';
4244

@@ -49,19 +51,10 @@ export const validDnsOrders: DnsOrder[] = [
4951

5052
let defaultDnsOrder: DnsOrder = 'verbatim';
5153

52-
// eslint-disable-next-line @typescript-eslint/require-await
53-
export async function getServers(): Promise<string[]> {
54+
export function getServers(): ReturnType<(typeof dns)['getServers']> {
5455
return ['1.1.1.1', '2606:4700:4700::1111', '1.0.0.1', '2606:4700:4700::1001'];
5556
}
5657

57-
export type LookupOptions = {
58-
family?: number | string;
59-
hints?: number;
60-
all?: boolean;
61-
order?: string;
62-
verbatim?: boolean;
63-
};
64-
6558
export type LookupCallback = (
6659
err: Error | null,
6760
address?: string | { address: string; family: number }[],
@@ -70,7 +63,7 @@ export type LookupCallback = (
7063

7164
export function lookup(
7265
hostname: string,
73-
options?: LookupOptions | LookupCallback,
66+
options?: dns.LookupOptions | LookupCallback,
7467
callback?: LookupCallback
7568
): void {
7669
let family: 0 | 4 | 6 = 0;
@@ -442,8 +435,7 @@ export function getDefaultResultOrder(): DnsOrder {
442435
return defaultDnsOrder;
443436
}
444437

445-
// eslint-disable-next-line @typescript-eslint/require-await
446-
export async function setServers(): Promise<void> {
438+
export function setServers(): void {
447439
// This function does not apply to workerd model.
448440
// Our implementation always use Cloudflare DNS and does not
449441
// allow users to change the underlying DNS server.

src/node/internal/internal_dns_promises.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// Copyright (c) 2017-2022 Cloudflare, Inc.
2+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3+
// https://opensource.org/licenses/Apache-2.0
4+
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
5+
6+
import type dns from 'node:dns/promises';
7+
import type {
8+
LookupAddress,
9+
LookupAllOptions,
10+
LookupOneOptions,
11+
LookupOptions,
12+
} from 'node:dns';
113
import * as errorCodes from 'node-internal:internal_dns_constants';
214
import {
315
reverse,
@@ -20,7 +32,6 @@ import {
2032
lookupService,
2133
resolve,
2234
resolveAny,
23-
type LookupOptions,
2435
} from 'node-internal:internal_dns';
2536
import {
2637
CAA,
@@ -54,41 +65,43 @@ export {
5465
resolveAny,
5566
} from 'node-internal:internal_dns';
5667

57-
export class Resolver {
58-
// eslint-disable-next-line @typescript-eslint/require-await
59-
async cancel(): Promise<void> {
68+
export class Resolver implements dns.Resolver {
69+
cancel(): void {
6070
// TODO(soon): Implement this.
6171
throw new Error('Not implemented');
6272
}
6373

64-
// eslint-disable-next-line @typescript-eslint/require-await
65-
async setLocalAddress(): Promise<void> {
74+
setLocalAddress(): void {
6675
// Does not apply to workerd implementation
6776
throw new Error('Not implemented');
6877
}
6978

70-
getServers(): Promise<string[]> {
79+
getServers(): string[] {
7180
return getServers();
7281
}
7382

83+
// @ts-expect-error TS2769 No matching overload.
7484
resolve(name: string, rrtype: string): ReturnType<typeof resolve> {
7585
return resolve(name, rrtype);
7686
}
7787

88+
// @ts-expect-error TS2769 No matching overload.
7889
resolve4(
7990
input: string,
8091
options?: { ttl?: boolean }
8192
): Promise<(string | TTLResponse)[]> {
8293
return resolve4(input, options);
8394
}
8495

96+
// @ts-expect-error TS2769 No matching overload.
8597
resolve6(
8698
input: string,
8799
options?: { ttl?: boolean }
88100
): Promise<(string | TTLResponse)[]> {
89101
return resolve6(input, options);
90102
}
91103

104+
// @ts-expect-error TS2769 No matching overload.
92105
resolveAny(): Promise<void> {
93106
return resolveAny();
94107
}
@@ -133,16 +146,18 @@ export class Resolver {
133146
return reverse(name);
134147
}
135148

136-
setServers(): Promise<void> {
137-
return setServers();
149+
setServers(): void {
150+
setServers();
138151
}
139152
}
140153

141154
export function lookup(
142155
hostname: string,
143-
options?: LookupOptions
144-
): Promise<unknown> {
145-
const { promise, resolve, reject } = Promise.withResolvers();
156+
options?: LookupOptions | LookupOneOptions | LookupAllOptions
157+
): Promise<LookupAddress | LookupAddress[]> {
158+
const { promise, resolve, reject } = Promise.withResolvers<
159+
LookupAddress | LookupAddress[]
160+
>();
146161
internalLookup(hostname, options, (error, address, family) => {
147162
if (error) {
148163
reject(error);
@@ -152,7 +167,7 @@ export function lookup(
152167
resolve({
153168
address,
154169
family,
155-
});
170+
} as LookupAddress);
156171
}
157172
});
158173
return promise;

src/node/internal/internal_net.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,12 @@ Socket.prototype._final = function (
650650
);
651651
};
652652

653-
// @ts-expect-error TS2322 No easy way to enable this.
654653
Socket.prototype.end = function (
655654
this: Socket,
656-
data: string | Uint8Array,
657-
encoding?: NodeJS.BufferEncoding,
658-
cb?: () => void
655+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
656+
data?: string | Uint8Array | NodeJS.BufferEncoding | VoidFunction,
657+
encoding?: NodeJS.BufferEncoding | VoidFunction,
658+
cb?: VoidFunction
659659
): Socket {
660660
// @ts-expect-error this fails after upgrading to @types/[email protected]
661661
Duplex.prototype.end.call(this, data, encoding, cb);
@@ -1404,7 +1404,7 @@ export function tryReadStart(socket: Socket): void {
14041404
function writeAfterFIN(
14051405
this: Socket,
14061406
chunk: Uint8Array | string,
1407-
encoding?: NodeJS.BufferEncoding | null,
1407+
encoding?: NodeJS.BufferEncoding | null | ((err?: Error) => void),
14081408
cb?: (err?: Error) => void
14091409
): boolean {
14101410
if (!this.writableEnded) {
@@ -1431,7 +1431,6 @@ function writeAfterFIN(
14311431

14321432
function onReadableStreamEnd(this: Socket): void {
14331433
if (!this.allowHalfOpen) {
1434-
// @ts-expect-error TS2554 Required due to @types/node
14351434
this.write = writeAfterFIN;
14361435
}
14371436
}

src/node/internal/streams_readable.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// Copyright (c) 2017-2022 Cloudflare, Inc.
2+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3+
// https://opensource.org/licenses/Apache-2.0
4+
15
import { Readable as _Readable } from 'node:stream';
26

37
export declare class Readable extends _Readable {
4-
destroyed: boolean;
58
_readableState?: {
69
readingMore: boolean;
710
};

0 commit comments

Comments
 (0)