Types
The public types prefID exports, so you can annotate your own functions and stores.
PrefixedId
The core type. PrefixedId<P> is a template literal type describing any string that starts with ${P}_.
ts
type PrefixedId<P extends string = string> = `${P}_${string}`;ts
import type { PrefixedId } from "prefid";
type UserId = PrefixedId<"user">;
// = `user_${string}`
function getUser(id: UserId) { /* ... */ }
getUser("user_abc"); // ✅
getUser("order_abc"); // ❌ not assignable to `user_${string}`IdOptions & IdGenerator
IdOptions is the options object accepted by createId, and IdGenerator is the type of the generator function it returns.
ts
import type { IdOptions, IdGenerator } from "prefid";
const options: IdOptions = { size: 16, separator: "_" };
const gen: IdGenerator = createId(options);EnsureUniqueOptions
The options object accepted by ensureUnique — currently just maxAttempts.