【发布时间】:2020-10-07 19:46:12
【问题描述】:
我一直在尝试将现有项目(从 Node.js)转换为 TypeScript。
对于上下文,我使用的是 http-status 包 (https://www.npmjs.com/package/http-status)
我正在尝试将变量传递到其默认导出中,但出现错误:
import status = require("http-status");
status.OK; // this works
status["OK"] // this also works
let str = "OK";
status[str]; // error
错误:
元素隐式具有“any”类型,因为“string”类型的表达式不能用于索引“HttpStatus”类型。
在“HttpStatus”类型上找不到带有“字符串”类型参数的索引签名。
如何将此用法转换为 TypeScript?
【问题讨论】:
标签: node.js typescript