【发布时间】:2018-02-24 13:41:57
【问题描述】:
我有这个枚举
enum methods {
DELETE = 1,
POST,
PUT,
GET
}
我想要一个函数接受一个参数,该参数可以是methods 枚举的键之一。
const getMethodPriority = (method /* how do I type this? */) => {
return methods[method];
};
因此,例如 getMethodPriority("DELETE") 将返回 1。
如何输入method 参数?
【问题讨论】:
-
你可以和
(method: keyof typeof methods)一起去
标签: typescript