From 621a84af1b418374c6b36cd4f1b049298bdd9fe2 Mon Sep 17 00:00:00 2001 From: Jonah Snider Date: Fri, 13 May 2022 19:55:51 -0700 Subject: [PATCH] fix: fix return type of `ConfigService#getOrThrow()` --- lib/config.service.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/config.service.ts b/lib/config.service.ts index ba172c6d..f8e1001f 100644 --- a/lib/config.service.ts +++ b/lib/config.service.ts @@ -146,7 +146,10 @@ export class ConfigService< * @param propertyPath * @param defaultValue */ - getOrThrow(propertyPath: KeyOf, defaultValue: NoInferType): T; + getOrThrow( + propertyPath: KeyOf, + defaultValue: NoInferType, + ): Exclude; /** * Get a configuration value (either custom configuration or process environment variable) * based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). @@ -160,7 +163,7 @@ export class ConfigService< propertyPath: P, defaultValue: NoInferType, options: ConfigGetOptions, - ): R; + ): Exclude; /** * Get a configuration value (either custom configuration or process environment variable) * based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). @@ -173,17 +176,17 @@ export class ConfigService< propertyPath: KeyOf, defaultValueOrOptions?: T | ConfigGetOptions, options?: ConfigGetOptions, - ): T { + ): Exclude { // @ts-expect-error Bypass method overloads - const value = this.get(propertyPath, defaultValueOrOptions, options) as T | undefined; + const value = this.get(propertyPath, defaultValueOrOptions, options) as + | T + | undefined; if (isUndefined(value)) { - throw new TypeError( - `Configuration key "${propertyPath}" does not exist`, - ); + throw new TypeError(`Configuration key "${propertyPath}" does not exist`); } - return value; + return value as Exclude; } private getFromCache(