@@ -114,7 +114,8 @@ export default function createFormatter(props: Props) {
114
114
115
115
function resolveFormatOrOptions < Options > (
116
116
typeFormats : Record < string , Options > | undefined ,
117
- formatOrOptions ?: string | Options
117
+ formatOrOptions ?: string | Options ,
118
+ overrides ?: Options
118
119
) {
119
120
let options ;
120
121
if ( typeof formatOrOptions === 'string' ) {
@@ -135,18 +136,23 @@ export default function createFormatter(props: Props) {
135
136
options = formatOrOptions ;
136
137
}
137
138
139
+ if ( overrides ) {
140
+ options = { ...options , ...overrides } ;
141
+ }
142
+
138
143
return options ;
139
144
}
140
145
141
146
function getFormattedValue < Options , Output > (
142
147
formatOrOptions : string | Options | undefined ,
148
+ overrides : Options | undefined ,
143
149
typeFormats : Record < string , Options > | undefined ,
144
150
formatter : ( options ?: Options ) => Output ,
145
151
getFallback : ( ) => Output
146
152
) {
147
153
let options ;
148
154
try {
149
- options = resolveFormatOrOptions ( typeFormats , formatOrOptions ) ;
155
+ options = resolveFormatOrOptions ( typeFormats , formatOrOptions , overrides ) ;
150
156
} catch {
151
157
return getFallback ( ) ;
152
158
}
@@ -164,12 +170,22 @@ export default function createFormatter(props: Props) {
164
170
function dateTime (
165
171
/** If a number is supplied, this is interpreted as a UTC timestamp. */
166
172
value : Date | number ,
167
- /** If a time zone is supplied, the `value` is converted to that time zone.
168
- * Otherwise the user time zone will be used. */
169
- formatOrOptions ?: FormatNames [ 'dateTime' ] | DateTimeFormatOptions
173
+ options ?: DateTimeFormatOptions
174
+ ) : string ;
175
+ function dateTime (
176
+ /** If a number is supplied, this is interpreted as a UTC timestamp. */
177
+ value : Date | number ,
178
+ format ?: FormatNames [ 'dateTime' ] ,
179
+ options ?: DateTimeFormatOptions
180
+ ) : string ;
181
+ function dateTime (
182
+ value : Date | number ,
183
+ formatOrOptions ?: FormatNames [ 'dateTime' ] | DateTimeFormatOptions ,
184
+ overrides ?: DateTimeFormatOptions
170
185
) {
171
186
return getFormattedValue (
172
187
formatOrOptions ,
188
+ overrides ,
173
189
formats ?. dateTime ,
174
190
( options ) => {
175
191
options = applyTimeZone ( options ) ;
@@ -184,12 +200,25 @@ export default function createFormatter(props: Props) {
184
200
start : Date | number ,
185
201
/** If a number is supplied, this is interpreted as a UTC timestamp. */
186
202
end : Date | number ,
187
- /** If a time zone is supplied, the values are converted to that time zone.
188
- * Otherwise the user time zone will be used. */
189
- formatOrOptions ?: FormatNames [ 'dateTime' ] | DateTimeFormatOptions
203
+ options ?: DateTimeFormatOptions
204
+ ) : string ;
205
+ function dateTimeRange (
206
+ /** If a number is supplied, this is interpreted as a UTC timestamp. */
207
+ start : Date | number ,
208
+ /** If a number is supplied, this is interpreted as a UTC timestamp. */
209
+ end : Date | number ,
210
+ format ?: FormatNames [ 'dateTime' ] ,
211
+ options ?: DateTimeFormatOptions
212
+ ) : string ;
213
+ function dateTimeRange (
214
+ start : Date | number ,
215
+ end : Date | number ,
216
+ formatOrOptions ?: FormatNames [ 'dateTime' ] | DateTimeFormatOptions ,
217
+ overrides ?: DateTimeFormatOptions
190
218
) {
191
219
return getFormattedValue (
192
220
formatOrOptions ,
221
+ overrides ,
193
222
formats ?. dateTime ,
194
223
( options ) => {
195
224
options = applyTimeZone ( options ) ;
@@ -203,10 +232,21 @@ export default function createFormatter(props: Props) {
203
232
204
233
function number (
205
234
value : number | bigint ,
206
- formatOrOptions ?: FormatNames [ 'number' ] | NumberFormatOptions
235
+ options ?: NumberFormatOptions
236
+ ) : string ;
237
+ function number (
238
+ value : number | bigint ,
239
+ format ?: FormatNames [ 'number' ] ,
240
+ options ?: NumberFormatOptions
241
+ ) : string ;
242
+ function number (
243
+ value : number | bigint ,
244
+ formatOrOptions ?: FormatNames [ 'number' ] | NumberFormatOptions ,
245
+ overrides ?: NumberFormatOptions
207
246
) {
208
247
return getFormattedValue (
209
248
formatOrOptions ,
249
+ overrides ,
210
250
formats ?. number ,
211
251
( options ) => formatters . getNumberFormat ( locale , options ) . format ( value ) ,
212
252
( ) => String ( value )
@@ -289,7 +329,17 @@ export default function createFormatter(props: Props) {
289
329
type FormattableListValue = string | ReactElement ;
290
330
function list < Value extends FormattableListValue > (
291
331
value : Iterable < Value > ,
292
- formatOrOptions ?: FormatNames [ 'list' ] | Intl . ListFormatOptions
332
+ options ?: Intl . ListFormatOptions
333
+ ) : Value extends string ? string : Iterable < ReactElement > ;
334
+ function list < Value extends FormattableListValue > (
335
+ value : Iterable < Value > ,
336
+ format ?: FormatNames [ 'list' ] ,
337
+ options ?: Intl . ListFormatOptions
338
+ ) : Value extends string ? string : Iterable < ReactElement > ;
339
+ function list < Value extends FormattableListValue > (
340
+ value : Iterable < Value > ,
341
+ formatOrOptions ?: FormatNames [ 'list' ] | Intl . ListFormatOptions ,
342
+ overrides ?: Intl . ListFormatOptions
293
343
) : Value extends string ? string : Iterable < ReactElement > {
294
344
const serializedValue : Array < string > = [ ] ;
295
345
const richValues = new Map < string , Value > ( ) ;
@@ -315,6 +365,7 @@ export default function createFormatter(props: Props) {
315
365
Value extends string ? string : Iterable < ReactElement >
316
366
> (
317
367
formatOrOptions ,
368
+ overrides ,
318
369
formats ?. list ,
319
370
// @ts -expect-error -- `richValues.size` is used to determine the return type, but TypeScript can't infer the meaning of this correctly
320
371
( options ) => {
0 commit comments