正在导入
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.发布于 2021-02-02 04:21:01
您需要在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());https://stackoverflow.com/questions/66003439
复制相似问题