Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot use d.ts file to load declaration merging

works fine perfectly when these are in the same file.

declare module "express-session" {
    interface SessionData {
        userId: number;
    }
}


static async loginUser(req: Request, res: Response) {
    const { email, password } = req.body;
    req.session!.userId = 1;
    return res.send("login");
}

However, if I seperate these files into,

index.d.ts index.ts

then it shows that userId does not exist within SessionData or Partial.

Why is this so?

like image 924
paul.kim1901 Avatar asked Oct 19 '25 10:10

paul.kim1901


1 Answers

Try to put your declaration into global.d.ts. See the docs

AFAIK, global.d.ts should be in the root directory.

If you want to put it into sibling file index.d.ts, please update typeRoots or types

like image 105
captain-yossarian Avatar answered Oct 22 '25 01:10

captain-yossarian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!