I’ve a custom type definition to augment an existing interface (Express Request
as shown here). Content of express.d.ts
:
declare namespace Express {
export interface Request {
name: string
}
}
Works fine. But instead of name
being a string, I need it to be a custom class MyClass
now. The class definition looks like:
export class MyClass {
first: string;
last: string;
}
I change the interface augmentation to:
import { MyClass } from "../routes/myClass";
declare namespace Express {
export interface Request {
name: MyClass
}
}
Now I get the following error when accessing req.name
:
error TS2339: Property 'name' does not exist on type 'Request'.
I’ve found out, that my express.d.ts
effectively becomes a “module” due to the added import
statement. Still, its not clear to me how I could overcome my problem.