createToken
function in meocord/common Since 4.1.0
createToken<T>(description: string): Token<T>Creates a token to provide and inject a value by, typed with what it provides.
Use one for a value that is not a class instance, such as a settings object, so TestingModule.get(TOKEN) and a
provider's useValue or useFactory are checked against its type. A class is its own token and needs none.
Parameters
| Name | Type | Description |
|---|---|---|
description | string | A name for the token, shown in errors and logs. |
Returns
Token<T>A new token.
Examples
export const SETTINGS = createToken<{ prefix: string }>('Settings')
@Service()
export class GreetingService {
constructor(@Inject(SETTINGS) private readonly settings: { prefix: string }) {}
}
@MeoCord({
controllers: [],
services: [GreetingService],
providers: [{ provide: SETTINGS, useValue: { prefix: '!' } }],
clientOptions: { intents: [GatewayIntentBits.Guilds] },
})
class App {}