【发布时间】:2022-01-25 09:55:08
【问题描述】:
假设我有这个
export type Hash = [ hashtype, hash ];
export type hashtype = -16 | -43 | 5 | 6;
export type hash = Buffer;
我想写一些东西来检查一个对象是否是一个哈希
未实施
isHash = (obj: any) => {
return (obj is Hash) // pseudo code, to implement
}
这样我才会有这样的回报:
isHash(5) => false // no hash
isHash([25, <Buffer ad 30>]) => false // 25 is not in hashType
isHash([5, <Buffer ad 30>]) => true // valid
【问题讨论】:
标签: javascript typescript types interface