From 58c5f64de3d10b1759dd3967cff4a9c3307f1d3a Mon Sep 17 00:00:00 2001 From: Pieter Develtere Date: Sun, 12 Jul 2026 18:21:54 +0200 Subject: [PATCH 1/2] fix: make TemporalValue self-contained, not the global Temporal namespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The emitted types.d.ts referenced `Temporal.*` bare, so consumers whose tsconfig lacks the `ESNext.Temporal` lib (all of TypeScript < 7) failed with `TS2503: Cannot find namespace 'Temporal'` — e.g. mysql2's typecheck after bumping to sql-escaper 1.5.0 (sidorares/node-mysql2#4216). Type TemporalValue structurally, branded on Symbol.toStringTag to match the runtime isTemporal check. Real Temporal values still assign; no global namespace, no ESNext.Temporal lib required downstream. Co-Authored-By: Claude Opus 4.8 --- src/index.ts | 2 +- src/types.ts | 17 ++++++++--------- tsconfig.json | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index b1e4bb2..2e536dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -460,7 +460,7 @@ export const temporalToString = ( value: TemporalValue, timezone?: Timezone ): string => { - if ('epochMilliseconds' in value) + if (typeof value.epochMilliseconds === 'number') return dateToString(new Date(value.epochMilliseconds), timezone || 'local'); if (value[Symbol.toStringTag] === 'Temporal.PlainDateTime') diff --git a/src/types.ts b/src/types.ts index 45593a9..2064059 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,15 +2,14 @@ export type Raw = { toSqlString(): string; }; -export type TemporalValue = - | Temporal.Instant - | Temporal.ZonedDateTime - | Temporal.PlainDateTime - | Temporal.PlainDate - | Temporal.PlainTime - | Temporal.PlainYearMonth - | Temporal.PlainMonthDay - | Temporal.Duration; +// Structural match for Temporal objects, branded on Symbol.toStringTag like the +// runtime `isTemporal` check. Avoids the global `Temporal` namespace so consumers +// don't need TS's ESNext.Temporal lib (TS2503 for TypeScript < 7). +export type TemporalValue = { + readonly [Symbol.toStringTag]: `Temporal.${string}`; + readonly epochMilliseconds?: number; + toString(): string; +}; export type SqlValue = | string diff --git a/tsconfig.json b/tsconfig.json index 66b7bd6..35d8f04 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "include": ["src"], "compilerOptions": { "target": "ES2018", - "lib": ["ES2018", "ESNext.Temporal"], + "lib": ["ES2018"], "module": "Node16", "moduleResolution": "Node16", "rootDir": "src", From b07f328edc4746b8de516e3af2e759e6a79ba5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Sun, 12 Jul 2026 13:37:02 -0300 Subject: [PATCH 2/2] Apply suggestion from @wellwelwel --- src/types.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/types.ts b/src/types.ts index 2064059..f857ce1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,9 +2,7 @@ export type Raw = { toSqlString(): string; }; -// Structural match for Temporal objects, branded on Symbol.toStringTag like the -// runtime `isTemporal` check. Avoids the global `Temporal` namespace so consumers -// don't need TS's ESNext.Temporal lib (TS2503 for TypeScript < 7). +/** Avoids the global `Temporal` namespace so consumers don't need TS's ESNext.Temporal lib. */ export type TemporalValue = { readonly [Symbol.toStringTag]: `Temporal.${string}`; readonly epochMilliseconds?: number;