@@ -30,7 +30,8 @@ export type InterpolationParameters = Record<string, any>;
3030export type StrictTranslation = string | StrictTranslation [ ] | TranslationObject | undefined | null ;
3131
3232// eslint-disable-next-line @typescript-eslint/no-explicit-any
33- export type Translation < T = any > = StrictTranslation | T ;
33+ export type AnyTranslation = any ;
34+ export type Translation < T = AnyTranslation > = StrictTranslation | T ;
3435
3536export interface TranslationObject {
3637 [ key : string ] : StrictTranslation ;
@@ -98,28 +99,28 @@ export abstract class ITranslateService {
9899 public abstract reloadLang ( lang : Language ) : Observable < InterpolatableTranslationObject > ;
99100 public abstract resetLang ( lang : Language ) : void ;
100101
101- public abstract instant (
102+ public abstract instant < T = AnyTranslation > (
102103 key : string | string [ ] ,
103104 interpolateParams ?: InterpolationParameters ,
104- ) : Translation ;
105- public abstract stream (
105+ ) : Translation < T > ;
106+ public abstract stream < T = AnyTranslation > (
106107 key : string | string [ ] ,
107108 interpolateParams ?: InterpolationParameters ,
108- ) : Observable < Translation > ;
109- public abstract getStreamOnTranslationChange (
109+ ) : Observable < Translation < T > > ;
110+ public abstract getStreamOnTranslationChange < T = AnyTranslation > (
110111 key : string | string [ ] ,
111112 interpolateParams ?: InterpolationParameters ,
112- ) : Observable < Translation > ;
113+ ) : Observable < Translation < T > > ;
113114
114115 public abstract set (
115116 key : string ,
116117 translation : string | TranslationObject ,
117118 lang ?: Language ,
118119 ) : void ;
119- public abstract get (
120+ public abstract get < T = AnyTranslation > (
120121 key : string | string [ ] ,
121122 interpolateParams ?: InterpolationParameters ,
122- ) : Observable < Translation > ;
123+ ) : Observable < Translation < T > > ;
123124
124125 public abstract setTranslation (
125126 lang : Language ,
@@ -185,7 +186,7 @@ export class TranslateService implements ITranslateService {
185186 private missingTranslationHandler = inject ( MissingTranslationHandler ) ;
186187 private store : TranslateStore = inject ( TranslateStore ) ;
187188
188- private readonly extend :boolean = false ;
189+ private readonly extend : boolean = false ;
189190
190191 /**
191192 * An Observable to listen to translation change events
@@ -506,10 +507,10 @@ export class TranslateService implements ITranslateService {
506507 * Gets the translated value of a key (or an array of keys)
507508 * @returns the translated key, or an object of translated keys
508509 */
509- public get (
510+ public get < T = AnyTranslation > (
510511 key : string | string [ ] ,
511512 interpolateParams ?: InterpolationParameters ,
512- ) : Observable < Translation > {
513+ ) : Observable < Translation < T > > {
513514 if ( ! isDefinedAndNotNull ( key ) || ! key . length ) {
514515 throw new Error ( `Parameter "key" is required and cannot be empty` ) ;
515516 }
@@ -530,10 +531,10 @@ export class TranslateService implements ITranslateService {
530531 * whenever the translation changes.
531532 * @returns A stream of the translated key, or an object of translated keys
532533 */
533- public getStreamOnTranslationChange (
534+ public getStreamOnTranslationChange < T = AnyTranslation > (
534535 key : string | string [ ] ,
535536 interpolateParams ?: InterpolationParameters ,
536- ) : Observable < Translation > {
537+ ) : Observable < Translation < T > > {
537538 if ( ! isDefinedAndNotNull ( key ) || ! key . length ) {
538539 throw new Error ( `Parameter "key" is required and cannot be empty` ) ;
539540 }
@@ -554,10 +555,10 @@ export class TranslateService implements ITranslateService {
554555 * whenever the language changes.
555556 * @returns A stream of the translated key, or an object of translated keys
556557 */
557- public stream (
558+ public stream < T = AnyTranslation > (
558559 key : string | string [ ] ,
559560 interpolateParams ?: InterpolationParameters ,
560- ) : Observable < Translation > {
561+ ) : Observable < Translation < T > > {
561562 if ( ! isDefinedAndNotNull ( key ) || ! key . length ) {
562563 throw new Error ( `Parameter "key" required` ) ;
563564 }
@@ -578,8 +579,7 @@ export class TranslateService implements ITranslateService {
578579 * All rules regarding the current language, the preferred language of even fallback languages
579580 * will be used except any promise handling.
580581 */
581- // eslint-disable-next-line @typescript-eslint/no-explicit-any
582- public instant < T = any > (
582+ public instant < T = AnyTranslation > (
583583 key : string | string [ ] ,
584584 interpolateParams ?: InterpolationParameters ,
585585 ) : Translation < T > {
0 commit comments