Skip to content

Commit a2c04b3

Browse files
committed
fix: widen tother type
1 parent 2543fe1 commit a2c04b3

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createTestTranslation } from './test.namespace';
2+
3+
export default createTestTranslation('de-DE', {
4+
hello: 'Hallo!',
5+
});

apps/mmstack/src/app/locale/test.register.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const r = registerNamespace(
44
() => import('./test.namespace').then((m) => m.default),
55
{
66
'sl-SI': () => import('./test.sl').then((m) => m.default),
7+
'de-DE': () => import('./test.de').then((m) => m.default),
78
},
89
);
910

packages/translate/src/lib/register-namespace.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
Signal,
77
untracked,
88
} from '@angular/core';
9-
import { CompiledTranslation, inferCompiledTranslationMap } from './compile';
9+
import {
10+
CompiledTranslation,
11+
inferCompiledTranslationMap,
12+
inferCompiledTranslationNamespace,
13+
} from './compile';
1014
import { replaceWithDelim } from './delim';
1115
import { UnknownStringKeyObject } from './string-key-object.type';
1216
import { TranslationStore } from './translation-store';
@@ -102,10 +106,18 @@ export function createT<TMap extends AnyStringRecord>(
102106

103107
export function registerNamespace<
104108
TDefault extends CompiledTranslation<UnknownStringKeyObject, string>,
105-
TOther extends CompiledTranslation<UnknownStringKeyObject, string>,
106109
>(
107110
defaultTranslation: () => Promise<TDefault>,
108-
other: Record<string, () => Promise<TOther>>,
111+
other: Record<
112+
string,
113+
() => Promise<
114+
CompiledTranslation<
115+
UnknownStringKeyObject,
116+
inferCompiledTranslationNamespace<TDefault>,
117+
string
118+
>
119+
>
120+
>,
109121
) {
110122
type $Map = inferCompiledTranslationMap<TDefault>;
111123
type $BaseTFN = TFunction<$Map>;
@@ -121,7 +133,7 @@ export function registerNamespace<
121133
const resolver = async () => {
122134
const store = inject(TranslationStore);
123135
const locale = untracked(store.locale);
124-
const tPromise = other[locale] as (() => Promise<TOther>) | undefined;
136+
const tPromise = other[locale] as (typeof other)[string] | undefined;
125137

126138
const promise = tPromise ?? defaultTranslation;
127139
if (!promise && isDevMode()) {

0 commit comments

Comments
 (0)