云函数中的Nanoid Typescript-错误:typeof导入没有调用签名

云函数中的Nanoid Typescript-错误:typeof导入没有调用签名,typescript,api,google-cloud-functions,Typescript,Api,Google Cloud Functions,进口 import * as customAlphabet from "nanoid"; var id: string = "" const alphabet: string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; function generateID() { id = customAlphabet(alphabet,10) cons

进口

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.

您需要在上调用
customAlphabet
。这将为您提供一个生成器函数。您可以调用此生成器,使用自定义字母表集和自定义长度生成随机字符串

从“nanoid”导入*为nanoid;
//你的字母表
常量字母='0123456789ABCD';
//生成器是一个返回随机字符串的函数
//长度为10,字母表由'alphabet'常量中的字符组成
常量生成器=nanoid.customAlphabet(字母表,10);
//一些随机字符串
console.log(生成器());
//另一个随机字符串
console.log(生成器());

您安装了吗?是的,安装了ThatThreaded id=(自定义字母表)(字母表,10)。。。它现在没有抛出错误,但不知道如何以任何其他方式修复它谢谢Bhai!这起作用了。谢谢你的帮助@如果这个答案帮助你解决了你的问题,请考虑。