【发布时间】:2020-03-20 00:01:36
【问题描述】:
我正在尝试克隆和运行一个开源项目 repo,并且很难解决这个问题,npm start 失败并出现“编译失败错误”,并说明了以下原因。
“{}”类型的参数不能分配给“Uint8Array”类型的参数
const [encChallenge] = await waitEvent(socket, 'data')
const challenge = decrypt(encChallenge) //This line causes the error
在decrypt函数之后
/** Decrypt data used shared key */
function decrypt(data: Uint8Array) {
if (!sharedKey) return null
const nonce = data.slice(0, sodium.crypto_box_NONCEBYTES)
const box = data.slice(sodium.crypto_box_NONCEBYTES, data.length)
const msg = crypto.decrypt(box, nonce, sharedKey)
return msg
}
将参数更改为any 解决了它,但我不能这样做,
如何将我的参数转换为 Unit8Array?
【问题讨论】:
-
答案很简单,
encChallenge不是来自Uint8Array类型,但您的方法decrypt需要一个。 waitEvent 自然返回什么类型?
标签: node.js typescript npm yarnpkg es6-modules