导入
import * as customAlphabet from "nanoid";
var id: string = ""
const alphabet: string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
function generateID() {
id = customAlphabet(alphabet,10)
console.log(id)
}
错误
id = customAlphabet(alphabet,10)
This expression is not callable.
Type 'typeof import("/Users/../API/functions/node_modules/nanoid/index")' has no call signatures.
最佳答案
您需要在 imported module 上调用 customAlphabet
。这为您提供了一个生成器函数。您可以调用此生成器使用自定义字母集和自定义长度生成随机字符串。
import * as nanoid from "nanoid";
// Your alphabet set
const alphabet = '0123456789ABCD';
// generator is a function that returns a random string
// of length 10, with alphabets from the characters in `alphabet` constant
const generator = nanoid.customAlphabet(alphabet, 10);
// some random string
console.log(generator());
// another random string
console.log(generator());
关于typescript - 云函数中的 Nanoid Typescript - 错误 : typeof import has no call signatures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66003439/