Typescript Node.js应用程序中的guid/uuid
我尝试在Node/Typescript应用程序中使用Typescript Node.js应用程序中的guid/uuid,node.js,typescript,uuid,guid,Node.js,Typescript,Uuid,Guid,我尝试在Node/Typescript应用程序中使用uuid(v3.0.1)包,但我不确定应该导入什么以及如何使用它 这是index.d.ts(来自@types/uuidv2.0.29): 我在这里找不到导出类 例如,angular2 uuid中的index.d.ts如下所示: export declare class UUID { constructor(); static UUID(): string; private static pad4(num); pr
uuid
(v3.0.1)包,但我不确定应该导入什么以及如何使用它
这是index.d.ts
(来自@types/uuid
v2.0.29):
我在这里找不到导出类
例如,angular2 uuid
中的index.d.ts
如下所示:
export declare class UUID {
constructor();
static UUID(): string;
private static pad4(num);
private static random4();
}
使用起来很明显:
let id = UUID.UUID();
所以。如何根据测试使用(导入和调用)uuid
?:
是的,以下是我的项目代码:
import { v4 as uuid } from 'uuid';
const id: string = uuid();
注意:要安装定义,需要运行
npm install --save-dev @types/uuid
这也适用于我:
从“uuid/v4”导入uuidv4
this.projectId=uuidv4()
那太好了!谢谢,但是。。。是否有任何方法可以使用import{}from”“
typescript样式?这对typescript最有效。最重要的答案是抱怨linteror的任何警告,只是从“uuid”导入{v4}代码>这解决了我的问题。谢谢这不管用<代码>错误:node_modules/uuid/index.js未导出“v4”只是在最新版本的uuid模块上重新测试。一切正常。我建议你再问一个问题。你的实际软件包的类型版本不正确。确保它们匹配。
import { v4 as uuid } from 'uuid';
const id: string = uuid();
npm install --save-dev @types/uuid
import * as uuid from "uuid";
const id: string = uuid.v4();