Skip to content

Commit

Permalink
Remove lots of angle type casts, which break Node 23's new TS support
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jan 29, 2025
1 parent fa28c8e commit 601b956
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/admin/mockttp-admin-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function buildAdminServerModel(
})
});

return <any> {
return {
Query: {
mockedEndpoints: async (): Promise<MockedEndpointData[]> => {
return Promise.all((await mockServer.getMockedEndpoints()).map(buildMockedEndpointData));
Expand Down
2 changes: 1 addition & 1 deletion src/client/admin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export class AdminClient<Plugins extends { [key: string]: AdminPlugin<any, any>
this.subscriptionClient!.request(query).subscribe({
next: async (value) => {
if (value.data) {
const response = (<any> value.data)[fieldName];
const response = value.data[fieldName];
const result = query.transformResponse
? await query.transformResponse(response, { adminClient: this })
: response as Result;
Expand Down
5 changes: 3 additions & 2 deletions src/rules/requests/request-handler-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,9 @@ export class StreamHandlerDefinition extends Serializable implements RequestHand
let serializedEventData: StreamHandlerEventMessage | false =
_.isString(chunk) ? { type: 'string', value: chunk } :
_.isBuffer(chunk) ? { type: 'buffer', value: chunk.toString('base64') } :
(_.isArrayBuffer(chunk) || _.isTypedArray(chunk)) ? { type: 'arraybuffer', value: encodeBase64(<any> chunk) } :
_.isNil(chunk) && { type: 'nil' };
(_.isArrayBuffer(chunk) || _.isTypedArray(chunk))
? { type: 'arraybuffer', value: encodeBase64(chunk) }
: _.isNil(chunk) && { type: 'nil' };

if (!serializedEventData) {
callback(new Error(`Can't serialize streamed value: ${chunk.toString()}. Streaming must output strings, buffers or array buffers`));
Expand Down
8 changes: 4 additions & 4 deletions src/rules/requests/request-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class SimpleHandler extends SimpleHandlerDefinition {
writeHead(response, this.status, this.statusMessage, this.headers);

if (isSerializedBuffer(this.data)) {
this.data = Buffer.from(<any> this.data);
this.data = Buffer.from(this.data as any);
}

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

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

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

export class CloseConnectionHandler extends CloseConnectionHandlerDefinition {
async handle(request: OngoingRequest) {
const socket: net.Socket = (<any> request).socket;
const socket: net.Socket = (request as any).socket;
socket.end();
throw new AbortError('Connection closed intentionally by rule');
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/request-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const parseRequestBody = (
req: http.IncomingMessage | http2.Http2ServerRequest,
options: { maxSize: number }
) => {
let transformedRequest = <OngoingRequest> <any> req;
let transformedRequest = req as any as OngoingRequest;
transformedRequest.body = parseBodyStream(req, options.maxSize, () => req.headers);
};

Expand Down
2 changes: 1 addition & 1 deletion test/integration/manual-rule-building.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("Mockttp rule building", function () {
return expect((async () => { // Funky setup to handle sync & async failure for node & browser
await server.addRequestRules({
matchers: [new matchers.SimplePathMatcher('/')],
handler: <any> null
handler: null as any
})
})()).to.be.rejectedWith('Cannot create a rule with no handler');
});
Expand Down
8 changes: 4 additions & 4 deletions test/integration/subscriptions/client-error-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe("Client error subscription", () => {
await server.on('client-error', (e) => errorPromise.resolve(e));
await server.forGet("http://example.com/endpoint").thenReply(200, "Mock data");

const response = await fetch("http://example.com/endpoint", <any> {
const response = await fetch("http://example.com/endpoint", {
agent: new HttpsProxyAgent({
protocol: 'http',
host: 'localhost',
Expand All @@ -332,7 +332,7 @@ describe("Client error subscription", () => {
headers: {
"long-value": TOO_LONG_HEADER_VALUE
}
});
} as any);

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

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

const response = await fetch("https://example.com/endpoint", <any> {
const response = await fetch("https://example.com/endpoint", {
agent: new HttpsProxyAgent({
protocol: 'https',
host: 'localhost',
Expand All @@ -369,7 +369,7 @@ describe("Client error subscription", () => {
'host': 'example.com',
"long-value": TOO_LONG_HEADER_VALUE
}
});
} as any);

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

Expand Down
4 changes: 2 additions & 2 deletions test/integration/subscriptions/tls-error-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ describe("TLS error subscriptions", () => {
await badServer.forAnyRequest().thenPassThrough();

await expect(
fetch(goodServer.urlFor("/"), <any> {
fetch(goodServer.urlFor("/"), {
// Ignores proxy cert issues by using the proxy via plain HTTP
agent: new HttpsProxyAgent({
protocol: 'http',
host: 'localhost',
port: badServer.port
})
})
} as any)
).to.be.rejectedWith(/certificate/);

const tlsError = await seenTlsErrorPromise;
Expand Down

0 comments on commit 601b956

Please # to comment.