I am attempting to enhance the Express request object by adding a property called "forwardingUrl".
To achieve this, I utilized declaration merging in a file named ./typing.d.ts:
declare namespace Express {
export interface Request {
forwardingUrl: string;
}
}
Although I can access and use the property in the editor, I encounter an error during compilation:
Property 'forwardingUrl' does not exist on type 'Request<ParamsDictionary>'.
What could be causing this issue?
UPDATE
The section of code where the error arises:
import { Middleware, Request } from '@tsed/common';
import { Request as ExpressRequest } from 'express';
@Middleware()
export class Wso2ForwardingUrlParser {
async use(@Request() request: ExpressRequest) {
if (request.header('X_FORWARDED_HOST') && request.header('X_FORWARDED_PREFIX')) {
request.forwardingUrl = `https://${request.header('X_FORWARDED_HOST')}${request.header('X_FORWARDED_PREFIX')}`;
} else {
request.forwardingUrl = '';
}
}
}