他每个人,我正在重构一个NodeJS应用程序到TypeScript。我创建了always object destructuring,也为下面的代码块设置了alias while object destructuring,如你所见。那么如何在这里指定类型呢?
const {length: isRegistered} = await User.countDocuments({email: emailTo});发布于 2020-06-14 14:10:11
我倾向于输入User.countDocuments({email: emailTo})的返回类型,它应该类似于Promise<{ length: number, ... }>。这样,TypeScript将推断析构属性的类型。
另一种方法是更明确地输入const {length: isRegistered} : {length: number}。
https://stackoverflow.com/questions/62368929
复制相似问题