feat: improve config.get typing

This commit is contained in:
shiftinv 2022-09-04 14:35:05 +02:00
parent 8b66aab94d
commit 533ab24b2a
1 changed files with 6 additions and 5 deletions

View File

@ -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<T>(key: string, def: T): string | T;
function get<T>(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}'.`);
}