mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-21 10:54:08 +02:00
11 lines
386 B
TypeScript
11 lines
386 B
TypeScript
import { generateId } from "../../lib/generateId";
|
|
import type { Pair, PairWithId } from "./PairEditor";
|
|
|
|
// NOTE: Generic so callers keep whatever they passed in (eg. an EditablePair stays editable)
|
|
export function ensurePairId<T extends Pair>(p: T): T & PairWithId {
|
|
if (typeof p.id === "string") {
|
|
return p as T & PairWithId;
|
|
}
|
|
return { ...p, id: p.id ?? generateId() };
|
|
}
|