API Reference / @dasch-ng/utils / provideValue
Function: provideValue()
provideValue<
T>(provide,useValue,multi?):ValueProvider
Defined in: provide-helpers.ts:31
Creates a type-safe value provider for Angular dependency injection.
This helper ensures that the useValue matches the type of the injection token, preventing common type mismatches that can occur with plain provider objects.
Type Parameters
T
T
The type of the value to provide
Parameters
provide
The injection token or class to provide for
InjectionToken<T> | Type<T>
useValue
T
The value to inject (must match type T)
multi?
boolean
Optional flag to enable multi-provider (allows multiple values for the same token)
Returns
ValueProvider
A type-safe ValueProvider object
Example
typescript
import { InjectionToken } from '@angular/core';
import { provideValue } from '@dasch-ng/utils';
const API_URL = new InjectionToken<string>('API_URL');
// Type-safe: value must be a string
provideValue(API_URL, 'https://api.example.com');
// Type error: number is not assignable to string
// provideValue(API_URL, 123);