小编cta*_*ppy的帖子

打字稿和 Express js。更改 res json `Response` 类型

在打字稿中,我试图将 Express 的Response json对象覆盖为始终使用的特定类型的对象

例如,我想强制执行一种接口类型,如果不遵循以下格式,该接口类型就会出错

  return res.status(200).json({
    data: ["a", {"a": "b"}],
    success: true,
  });
Run Code Online (Sandbox Code Playgroud)

我尝试使用dts-gen --m express -f src/types/express.d.ts创建声明文件进行修改,但以失败告终。

有没有办法覆盖现有库上的特定类型,或者我是否需要创建特定于我的需求的声明文件?

node.js express type-declaration typescript

3
推荐指数
2
解决办法
9930
查看次数

标签 统计

express ×1

node.js ×1

type-declaration ×1

typescript ×1