-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
icu.macro.d.ts
103 lines (90 loc) · 2.95 KB
/
icu.macro.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { ReactElement } from 'react';
import { Trans } from './index.js';
import type { Namespace, TypeOptions, i18n, ParseKeys } from 'i18next';
export { Trans };
type _DefaultNamespace = TypeOptions['defaultNS'];
declare module 'react-i18next/icu.macro' {
export interface PluralSubProps<
Key extends ParseKeys<Ns, {}, ''>,
Ns extends Namespace = _DefaultNamespace,
> {
children?: never;
i18nKey?: Key;
i18n?: i18n;
ns?: Ns;
count: number;
values?: {};
zero?: string | ReactElement;
one?: string | ReactElement;
two?: string | ReactElement;
few?: string | ReactElement;
many?: string | ReactElement;
other: string | ReactElement;
}
type PluralProps<
T,
Key extends ParseKeys<Ns, {}, ''>,
Ns extends Namespace = _DefaultNamespace,
> = {
[P in keyof T]: P extends keyof PluralSubProps<Key, Ns>
? // support the standard properties of Plural
PluralSubProps<Key, Ns>[P]
: // this supports infinite $0={..} or $123={..}
// technically it also supports $-1={..} and $2.3={..} but we don't need to
// worry since that's invalid syntax.
P extends `$${number}`
? string | ReactElement
: never;
};
interface SelectSubProps {
[key: string]: string | ReactElement;
}
interface NoChildren {
children?: never;
}
interface SelectRequiredProps<
Key extends ParseKeys<Ns, {}, ''>,
Ns extends Namespace = _DefaultNamespace,
> extends NoChildren {
i18nKey?: Key;
i18n?: i18n;
ns?: Ns;
other: string | ReactElement;
}
// defining it this way ensures that `other` is always defined, but allows
// unlimited other select types.
type SelectProps<
Key extends ParseKeys<Ns, {}, ''>,
Ns extends Namespace = _DefaultNamespace,
> = SelectSubProps & SelectRequiredProps<Key, Ns>;
function Plural<T, Key extends ParseKeys<Ns, {}, ''>, Ns extends Namespace = _DefaultNamespace>(
props: PluralProps<T, Key, Ns> & NoChildren,
): ReactElement;
function SelectOrdinal<
T,
Key extends ParseKeys<Ns, {}, ''>,
Ns extends Namespace = _DefaultNamespace,
>(props: PluralProps<T, Key, Ns> & NoChildren): ReactElement;
function Select<Key extends ParseKeys<Ns, {}, ''>, Ns extends Namespace = _DefaultNamespace>(
props: SelectProps<Key, Ns>,
): ReactElement;
function date(strings: TemplateStringsArray, variable: Date): string;
function time(strings: TemplateStringsArray, variable: Date): string;
function number(strings: TemplateStringsArray, variable: number): string;
type ValidInterpolations = ReactElement | string;
function plural(
strings: TemplateStringsArray,
variable: number,
...args: ValidInterpolations[]
): string;
function selectOrdinal(
strings: TemplateStringsArray,
variable: number,
...args: ValidInterpolations[]
): string;
function select(
strings: TemplateStringsArray,
variable: string,
...args: ValidInterpolations[]
): string;
}