首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >云函数中的Nanoid类型-错误: typeof import没有调用签名

云函数中的Nanoid类型-错误: typeof import没有调用签名
EN

Stack Overflow用户
提问于 2021-02-02 03:55:30
回答 1查看 1.3K关注 0票数 2

正在导入

代码语言:javascript
复制
import * as customAlphabet from "nanoid";
var id: string = ""
const alphabet: string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

function generateID() {
      id = customAlphabet(alphabet,10)
      console.log(id)
}

误差

代码语言:javascript
复制
id = customAlphabet(alphabet,10)

This expression is not callable.
  Type 'typeof import("/Users/../API/functions/node_modules/nanoid/index")' has no call signatures.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-02 04:21:01

您需要在customAlphabet上调用进口模块。这给了你一个生成器的功能。您可以调用此生成器来使用自定义字母集和自定义长度生成随机字符串。

代码语言:javascript
复制
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());

码箱链接

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66003439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档