-
-
Notifications
You must be signed in to change notification settings - Fork 628
/
t.test.ts
54 lines (44 loc) · 1.25 KB
/
t.test.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
import i18next, { TFunction } from 'i18next';
function defaultNamespaceUsage(t: TFunction) {
t('bar');
t('foo');
}
function namedDefaultNamespaceUsage(t: TFunction<'alternate'>) {
t('foobar.barfoo');
t('foobar.deep.deeper.deeeeeper');
t('foobar.deep.deeper').deeeeeper;
}
function arrayNamespace(t: TFunction<['custom', 'alternate']>) {
t('alternate:baz');
t('alternate:foobar.deep').deeper.deeeeeper;
t('custom:bar');
}
// @ts-expect-error
function expectErrorWhenNamespaceDoesNotExist(t: TFunction<'foo'>) {}
function expectErrorWhenKeyNotInNamespace(t: TFunction<'alternate'>) {
// @ts-expect-error
t('bar');
}
function i18nextTUsage() {
i18next.t('alternate:foobar.barfoo');
i18next.t('alternate:foobar.deep').deeper.deeeeeper;
i18next.t('custom:bar');
}
function expectErrorWhenInvalidKeyWithI18nextT() {
// @ts-expect-error
i18next.t('custom:test');
}
function expectErrorWhenInvalidNamespaceWithI18nextT() {
// @ts-expect-error
i18next.t('test:bar');
}
function i18nextTPluralsUsage() {
i18next.t('plurals:foo', { count: 1 });
i18next.t('plurals:foo_many', { count: 10 });
}
// @ts-expect-error
function returnNullWithFalseValue(t: TFunction<string>) {
function fn(value: null) {}
// @ts-expect-error
fn(t('foo'));
}