【问题标题】:How to access to namespace in declare global?如何在声明全局中访问命名空间?
【发布时间】:2019-10-22 21:10:42
【问题描述】:

背景

我正在制作简单的网站,用户可以在其中更新图片。 所以,我使用 Multer 库和 Express with Typescript。

问题

我想使用File type of Multer。但是我不知道如何访问 Multer 命名空间。

declare global {
  namespace Express {
    interface Request {
      file: Multer.File;
      files: {
        [fieldname: string]: Multer.File[];
      } | Multer.File[];
    }

  namespace Multer {
    interface File {
      /** Field name specified in the form */
      fieldname: string;
      ...
}

我的最终目标是这个。

app.post('/admin/uploads', async (req, res) => {
    let file: Multer.File = req.files.myFile;
    console.log(file.filename);
    ....
}

如何访问 Multer 命名空间?

【问题讨论】:

  • 我也想访问命名空间之外的变量(例如文件名)...!

标签: node.js typescript express multer


【解决方案1】:
app.post('/admin/uploads', async (req, res) => {
    let file: Express.Multer.File = req.files.myFile;
    console.log(file.filename);
    ....
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-24
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多