-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
Currently, I'm doing this to allow type-safe environments.
export class EnvironmentService<TEnvironment extends BaseEnvironment> {
constructor(
private readonly configService: ConfigService<TEnvironment, true>,
) {}
get<Key extends keyof TEnvironment>(key: Key): TEnvironment[Key] {
// FIX: Create the proper type for ConfigService.getOrThrow
// @ts-expect-error: Type used by ConfigService is incorrect
return this.configService.getOrThrow(key);
}
}I'm looking for a way to provide the right type to the getOrThrow function of the ConfigService.
If I remove the @ts-expect-error directive, the message thrown by TypeScript is the following:
typescript: Argument of type 'Key' is not assignable to parameter of type 'KeyOf<TEnvironment>'.
Type 'keyof TEnvironment' is not assignable to type 'KeyOf<TEnvironment>'.
Type 'string | number | symbol' is not assignable to type 'KeyOf<TEnvironment>'.
Type 'string' is not assignable to type 'KeyOf<TEnvironment>'. [2345]
The KeyOf<T> type is an internal type of the ConfigService and has the following definition:
type KeyOf<T> = keyof T extends never ? string : keyof T;Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed