From 533ab24b2a89df7e8898a4fc18e30a6d51db853d Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sun, 4 Sep 2022 14:35:05 +0200 Subject: [PATCH] feat: improve config.get typing --- lib/config.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index 6503633..724155d 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,10 +1,11 @@ import { parseBool } from "./util.ts"; -function get(key: string, def?: string): string { - const value = Deno.env.get(key) ?? def; - if (value !== undefined) { - return value; - } +function get(key: string): string; +function get(key: string, def: T): string | T; +function get(key: string, def?: T): string | T { + const value = Deno.env.get(key); + if (value !== undefined) return value; + else if (def !== undefined) return def; throw new Error(`Missing environment variable '${key}'.`); }