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..f857ce1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,15 +2,12 @@ export type Raw = { toSqlString(): string; }; -export type TemporalValue = - | Temporal.Instant - | Temporal.ZonedDateTime - | Temporal.PlainDateTime - | Temporal.PlainDate - | Temporal.PlainTime - | Temporal.PlainYearMonth - | Temporal.PlainMonthDay - | Temporal.Duration; +/** 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; + 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",