Skip to content

Commit

Permalink
feat: improve orThrow methods typing
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Jul 27, 2023
1 parent b844c5d commit d7f7590
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/env/env.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export class EnvManager<E extends string, C extends BaseConfig = BaseConfig> ext
return this.cache.get(key) as EnvPicker<E, C[K] | undefined>;
}

public pickOrThrow<K extends keyof C>(key: K): EnvPicker<E, C[K]> {
public pickOrThrow<K extends keyof C>(key: K): EnvPicker<E, NonNullable<C[K]>> {
const value = this.source[key];

if (value === null || value === undefined || value.trim() === '') {
throw new Error(`key: ${key.toString()} is empty`);
}

return this.pick(key) as EnvPicker<E, C[K]>;
return this.pick(key) as EnvPicker<E, NonNullable<C[K]>>;
}

public pickFor<K extends keyof C>(envRecord: AtLeastOne<Record<E, K>>): EnvPicker<E, C[K] | undefined> {
Expand All @@ -67,7 +67,7 @@ export class EnvManager<E extends string, C extends BaseConfig = BaseConfig> ext
return this.pick(key) as EnvPicker<E, C[K] | undefined>;
}

public pickForOrThrow<K extends keyof C>(envRecord: AtLeastOne<Record<E, K>>): EnvPicker<E, C[K]> {
public pickForOrThrow<K extends keyof C>(envRecord: AtLeastOne<Record<E, K>>): EnvPicker<E, NonNullable<C[K]>> {
const key = this.getKeyOrThrow(envRecord);

return this.pickOrThrow(key as K);
Expand Down

0 comments on commit d7f7590

Please sign in to comment.