我尝试在Node/Typescript应用程序中使用uuid
(v 3.0.1)包,但我不确定应该导入什么以及如何使用它。
这是index.d.ts
(来自@types/uuid
版本2.0.29):
declare namespace uuid {
interface V1Options {
node?: number[];
clockseq?: number;
msecs?: number | Date;
nsecs?: number;
}
type V4Options = { random: number[] } | { rng: () => number[]; }
interface UuidStatic {
(options?: V4Options): string;
(options: V4Options | null, buffer: number[], offset?: number): number[];
(options: V4Options | null, buffer: Buffer, offset?: number): Buffer;
v1(options?: V1Options): string;
v1(options: V1Options | null, buffer: number[], offset?: number): number[];
v1(options: V1Options | null, buffer: Buffer, offset?: number): Buffer;
v4: UuidStatic;
parse(id: string): number[];
parse(id: string, buffer: number[], offset?: number): number[];
parse(id: string, buffer: Buffer, offset?: number): Buffer;
unparse(buffer: number[] | Buffer, offset?: number): string;
}
}
declare const uuid: uuid.UuidStatic
export = uuid
我在这里找不到汇出的类别。
例如,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
呢?
5条答案
按热度按时间bis0qfac1#
是的,下面是我的项目代码:
注意:要安装定义,需要运行
7gs2gvoe2#
根据测试:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/354cec620daccfa0ad167ba046651fb5fef69e8a/types/uuid/uuid-tests.ts
42fyovps3#
u59ebvdq4#
这也适用于我:
ix0qys7i5#
我按以下顺序为项目使用uuid