Skip to content

Commit 601b956

Browse files
committed
Remove lots of angle type casts, which break Node 23's new TS support
1 parent fa28c8e commit 601b956

File tree

8 files changed

+17
-16
lines changed

8 files changed

+17
-16
lines changed

src/admin/mockttp-admin-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function buildAdminServerModel(
138138
})
139139
});
140140

141-
return <any> {
141+
return {
142142
Query: {
143143
mockedEndpoints: async (): Promise<MockedEndpointData[]> => {
144144
return Promise.all((await mockServer.getMockedEndpoints()).map(buildMockedEndpointData));

src/client/admin-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ export class AdminClient<Plugins extends { [key: string]: AdminPlugin<any, any>
638638
this.subscriptionClient!.request(query).subscribe({
639639
next: async (value) => {
640640
if (value.data) {
641-
const response = (<any> value.data)[fieldName];
641+
const response = value.data[fieldName];
642642
const result = query.transformResponse
643643
? await query.transformResponse(response, { adminClient: this })
644644
: response as Result;

src/rules/requests/request-handler-definitions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ export class StreamHandlerDefinition extends Serializable implements RequestHand
413413
let serializedEventData: StreamHandlerEventMessage | false =
414414
_.isString(chunk) ? { type: 'string', value: chunk } :
415415
_.isBuffer(chunk) ? { type: 'buffer', value: chunk.toString('base64') } :
416-
(_.isArrayBuffer(chunk) || _.isTypedArray(chunk)) ? { type: 'arraybuffer', value: encodeBase64(<any> chunk) } :
417-
_.isNil(chunk) && { type: 'nil' };
416+
(_.isArrayBuffer(chunk) || _.isTypedArray(chunk))
417+
? { type: 'arraybuffer', value: encodeBase64(chunk) }
418+
: _.isNil(chunk) && { type: 'nil' };
418419

419420
if (!serializedEventData) {
420421
callback(new Error(`Can't serialize streamed value: ${chunk.toString()}. Streaming must output strings, buffers or array buffers`));

src/rules/requests/request-handlers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class SimpleHandler extends SimpleHandlerDefinition {
160160
writeHead(response, this.status, this.statusMessage, this.headers);
161161

162162
if (isSerializedBuffer(this.data)) {
163-
this.data = Buffer.from(<any> this.data);
163+
this.data = Buffer.from(this.data as any);
164164
}
165165

166166
if (this.trailers) {
@@ -408,7 +408,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
408408
let { protocol, hostname, port, path } = url.parse(reqUrl);
409409

410410
// Check if this request is a request loop:
411-
if (isSocketLoop(this.outgoingSockets, (<any> clientReq).socket)) {
411+
if (isSocketLoop(this.outgoingSockets, (clientReq as any).socket)) {
412412
throw new Error(oneLine`
413413
Passthrough loop detected. This probably means you're sending a request directly
414414
to a passthrough endpoint, which is forwarding it to the target URL, which is a
@@ -588,7 +588,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
588588

589589
if (modifiedReq?.response) {
590590
if (modifiedReq.response === 'close') {
591-
const socket: net.Socket = (<any> clientReq).socket;
591+
const socket: net.Socket = (clientReq as any).socket;
592592
socket.end();
593593
throw new AbortError('Connection closed intentionally by rule');
594594
} else if (modifiedReq.response === 'reset') {
@@ -1301,7 +1301,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
13011301

13021302
export class CloseConnectionHandler extends CloseConnectionHandlerDefinition {
13031303
async handle(request: OngoingRequest) {
1304-
const socket: net.Socket = (<any> request).socket;
1304+
const socket: net.Socket = (request as any).socket;
13051305
socket.end();
13061306
throw new AbortError('Connection closed intentionally by rule');
13071307
}

src/util/request-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export const parseRequestBody = (
272272
req: http.IncomingMessage | http2.Http2ServerRequest,
273273
options: { maxSize: number }
274274
) => {
275-
let transformedRequest = <OngoingRequest> <any> req;
275+
let transformedRequest = req as any as OngoingRequest;
276276
transformedRequest.body = parseBodyStream(req, options.maxSize, () => req.headers);
277277
};
278278

test/integration/manual-rule-building.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("Mockttp rule building", function () {
106106
return expect((async () => { // Funky setup to handle sync & async failure for node & browser
107107
await server.addRequestRules({
108108
matchers: [new matchers.SimplePathMatcher('/')],
109-
handler: <any> null
109+
handler: null as any
110110
})
111111
})()).to.be.rejectedWith('Cannot create a rule with no handler');
112112
});

test/integration/subscriptions/client-error-events.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe("Client error subscription", () => {
323323
await server.on('client-error', (e) => errorPromise.resolve(e));
324324
await server.forGet("http://example.com/endpoint").thenReply(200, "Mock data");
325325

326-
const response = await fetch("http://example.com/endpoint", <any> {
326+
const response = await fetch("http://example.com/endpoint", {
327327
agent: new HttpsProxyAgent({
328328
protocol: 'http',
329329
host: 'localhost',
@@ -332,7 +332,7 @@ describe("Client error subscription", () => {
332332
headers: {
333333
"long-value": TOO_LONG_HEADER_VALUE
334334
}
335-
});
335+
} as any);
336336

337337
expect(response.status).to.equal(431);
338338

@@ -357,7 +357,7 @@ describe("Client error subscription", () => {
357357
await server.on('client-error', (e) => errorPromise.resolve(e));
358358
await server.forGet("https://example.com/endpoint").thenReply(200, "Mock data");
359359

360-
const response = await fetch("https://example.com/endpoint", <any> {
360+
const response = await fetch("https://example.com/endpoint", {
361361
agent: new HttpsProxyAgent({
362362
protocol: 'https',
363363
host: 'localhost',
@@ -369,7 +369,7 @@ describe("Client error subscription", () => {
369369
'host': 'example.com',
370370
"long-value": TOO_LONG_HEADER_VALUE
371371
}
372-
});
372+
} as any);
373373

374374
expect(response.status).to.equal(431);
375375

test/integration/subscriptions/tls-error-events.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ describe("TLS error subscriptions", () => {
119119
await badServer.forAnyRequest().thenPassThrough();
120120

121121
await expect(
122-
fetch(goodServer.urlFor("/"), <any> {
122+
fetch(goodServer.urlFor("/"), {
123123
// Ignores proxy cert issues by using the proxy via plain HTTP
124124
agent: new HttpsProxyAgent({
125125
protocol: 'http',
126126
host: 'localhost',
127127
port: badServer.port
128128
})
129-
})
129+
} as any)
130130
).to.be.rejectedWith(/certificate/);
131131

132132
const tlsError = await seenTlsErrorPromise;

0 commit comments

Comments
 (0)