Skip to content

Commit

Permalink
provider generics
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Dec 29, 2023
1 parent d838835 commit c6de29e
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/config.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const createConfigInjectionToken = <T = unknown>(
...options,
},
);
const provider = (config: Partial<T>) => ({
const provider = <R extends T = T>(config: Partial<R>) => ({
provide: token,
useValue: {
...defaultConfig,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface DaffConfigInjectionToken<T = unknown> {
* It will shallow merge the passed config with the default config
* with the passed config keys taking precedence.
*/
provider: (config: Partial<T>) => ValueProvider;
provider: <R extends T = T>(config: Partial<R>) => ValueProvider;
}
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/multi.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const createMultiInjectionToken = <T = unknown>(
...options,
},
);
const provider = (...values: Array<T>) => values.map((value) => ({
const provider = <R extends T = T>(...values: Array<R>) => values.map((value) => ({
provide: token,
useValue: value,
multi: true,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/multi.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface DaffMultiInjectionToken<T = unknown> {
/**
* A helper function to provide values to the token.
*/
provider: (...values: Array<T>) => Array<ValueProvider>;
provider: <R extends T = T>(...values: Array<R>) => Array<ValueProvider>;
}
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/services.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const createServicesInjectionToken = <T = unknown>(
...options,
},
);
const provider = (...classes: Array<Type<T>>) => classes.map((klass) => ({
const provider = <R extends T = T>(...classes: Array<Type<R>>) => classes.map((klass) => ({
provide: token,
useExisting: klass,
multi: true,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/services.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface DaffServicesInjectionToken<T = unknown> {
/**
* A helper function to provide service classes to the token.
*/
provider: (...classes: Array<Type<T>>) => Array<ExistingProvider>;
provider: <R extends T = T>(...classes: Array<Type<R>>) => Array<ExistingProvider>;
}
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/single.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DaffSingleInjectionToken } from './single.type';
*/
export const createSingleInjectionToken = <T = unknown>(...args: ConstructorParameters<typeof InjectionToken<T>>): DaffSingleInjectionToken<T> => {
const token = new InjectionToken<T>(...args);
const provider = (value: T) => ({
const provider = <R extends T = T>(value: R) => ({
provide: token,
useValue: value,
});
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/injection-tokens/single.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export interface DaffSingleInjectionToken<T = unknown> {
/**
* A helper function to provide a value to the token.
*/
provider: (value: T) => ValueProvider;
provider: <R extends T = T>(value: R) => ValueProvider;
}

0 comments on commit c6de29e

Please sign in to comment.