Skip to content

Commit

Permalink
Merge pull request #23 from levabala/master
Browse files Browse the repository at this point in the history
fix(v4): narrow return type
  • Loading branch information
eugenehp authored Jul 16, 2024
2 parents c436906 + b140a6a commit e4179c5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ type V4Options = {
rng?: () => number[];
};

// signature overloads to narrow return type
export function v4(
options?: V4Options | string,
buf?: undefined,
offset?: number,
): string;
export function v4(
options: V4Options | string | undefined,
buf: Array<number>,
offset?: number,
): number[];

// **`v4()` - Generate random UUID**
// See https://github.com/broofa/node-uuid for API details
export const v4 = (
export function v4(
options?: V4Options | string,
buf?: Array<number>,
offset?: number,
) => {
) {
// Deprecated - 'format' argument, as supported in v1.2
let i = (buf && offset) || 0;

Expand Down Expand Up @@ -44,4 +56,4 @@ export const v4 = (
}

return buf || unparse(rnds);
};
}

0 comments on commit e4179c5

Please sign in to comment.