Skip to content

Commit c5c8ab9

Browse files
authored
fix: Tighten TemporalObject type to improve FluentVariable type safety (#649)
1 parent 9a18331 commit c5c8ab9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

fluent-bundle/src/types.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@ import { Scope } from "./scope.js";
44
// Replace with Temporal.* types once they are provided by TypeScript
55
// In addition to this minimal interface, these objects are also expected
66
// to be supported by Intl.DateTimeFormat
7-
interface TemporalObject {
8-
epochMilliseconds?: number;
7+
interface TemporalInstant {
8+
epochMilliseconds: number
9+
toString(): string;
10+
}
11+
interface TemporalDateTypes {
12+
calendarId: string;
913
toZonedDateTime?(timeZone: string): { epochMilliseconds: number };
10-
calendarId?: string;
1114
toString(): string;
1215
}
16+
interface TemporalPlainTime {
17+
hour: number
18+
minute: number
19+
second: number
20+
toString(): string;
21+
}
22+
type TemporalObject = TemporalInstant | TemporalDateTypes | TemporalPlainTime
1323

1424
export type FluentValue = FluentType<unknown> | string;
1525

@@ -207,7 +217,7 @@ export class FluentDateTime extends FluentType<number | Date | TemporalObject> {
207217
if (value instanceof Date) return value.getTime();
208218

209219
if ("epochMilliseconds" in value) {
210-
return value.epochMilliseconds as number;
220+
return value.epochMilliseconds;
211221
}
212222

213223
if ("toZonedDateTime" in value) {

0 commit comments

Comments
 (0)