简体   繁体   English

无法使用 d.ts 文件加载声明合并

[英]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索引.d.ts 索引.ts

then it shows that userId does not exist within SessionData or Partial.然后它表明 SessionData 或 Partial 中不存在 userId。

Why is this so?为什么会这样?

Try to put your declaration into global.d.ts .尝试将您的声明放入global.d.ts See the docs查看文档

AFAIK, global.d.ts should be in the root directory. AFAIK,global.d.ts 应该在根目录中。

If you want to put it into sibling file index.d.ts , please update typeRoots or types如果要将其放入同级文件index.d.ts中,请更新typeRootstypes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM