我似乎无法理解这到底是什么。
如何为该基本库创建类型? https://github.com/deanilvincent/check-password-strength/blob/master/index.js
这是我到目前为止所得到的:
declare module 'check-password-strength' {
function check_password_strength(password:any): any;
export = check_password_strength;
}
但是它如何工作?该库称为检查密码强度。当我使用check_password_strength创建函数时,如何仍能正常工作? (是的,此代码实际上有效。) 我这样使用它:
import check_password_strength from 'check-password-strength'
check_password_strength(body.password)
问题是,除了我不明白为什么它用_而不是-(尽管-不能工作)为什么我不能用-来实现功能。 Typescript如何知道应该调用该函数?下一个问题是,如何更改上面的d.ts文件,以实际上为我提供正确的返回类型(用于智能感知)。
它返回如下所示的元组:
strength = {
id: 2,
value: 'Strong'
}
如何在上面的代码中实现它?
答案 0 :(得分:0)
我为问题2随机找到了解决方案,但是我仍然不知道,当我使用_时,打字稿怎么可能调用check-password-strength。
答案是:
function check_password_strength(password:any): {id: number, value: string};