@@ -4,6 +4,7 @@ import type {
4
4
$Dictionary ,
5
5
$SpecialObject ,
6
6
$StringKeyPathToRecord ,
7
+ $NoInfer ,
7
8
} from './helpers.js' ;
8
9
import type {
9
10
TypeOptions ,
@@ -260,6 +261,12 @@ export type TFunctionDetailedResult<T = string, TOpt extends TOptions = {}> = {
260
261
usedParams : InterpolationMap < T > & { count ?: TOpt [ 'count' ] } ;
261
262
} ;
262
263
264
+ type TFunctionProcessReturnValue < Ret , DefaultValue > = Ret extends string | $SpecialObject | null
265
+ ? Ret
266
+ : [ DefaultValue ] extends [ never ]
267
+ ? Ret
268
+ : DefaultValue ;
269
+
263
270
type TFunctionReturnOptionalDetails < Ret , TOpt extends TOptions > = TOpt [ 'returnDetails' ] extends true
264
271
? TFunctionDetailedResult < Ret , TOpt >
265
272
: Ret ;
@@ -278,12 +285,13 @@ export interface TFunction<Ns extends Namespace = DefaultNamespace, KPrefix = un
278
285
const TOpt extends TOptions ,
279
286
Ret extends TFunctionReturn < Ns , AppendKeyPrefix < Key , KPrefix > , TOpt > ,
280
287
const ActualOptions extends TOpt & InterpolationMap < Ret > = TOpt & InterpolationMap < Ret > ,
288
+ DefaultValue extends string = never ,
281
289
> (
282
290
...args :
283
291
| [ key : Key | Key [ ] , options ?: ActualOptions ]
284
- | [ key : string | string [ ] , options : TOpt & $Dictionary & { defaultValue : string } ]
285
- | [ key : string | string [ ] , defaultValue : string , options ?: TOpt & $Dictionary ]
286
- ) : TFunctionReturnOptionalDetails < Ret , TOpt > ;
292
+ | [ key : string | string [ ] , options : TOpt & $Dictionary & { defaultValue : DefaultValue } ]
293
+ | [ key : string | string [ ] , defaultValue : DefaultValue , options ?: TOpt & $Dictionary ]
294
+ ) : TFunctionReturnOptionalDetails < TFunctionProcessReturnValue < $NoInfer < Ret > , DefaultValue > , TOpt > ;
287
295
}
288
296
289
297
export type KeyPrefix < Ns extends Namespace > = ResourceKeys < true > [ $FirstNamespace < Ns > ] | undefined ;
0 commit comments