Skip to content

Commit

Permalink
Fix inferred DotenvStrictParseOutput types and update naming conven…
Browse files Browse the repository at this point in the history
…tions (#130)
  • Loading branch information
aaronccasanova committed Sep 13, 2023
1 parent 009f470 commit d1d5a52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-pets-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'dotenv-strict': patch
---

Fixed inferred `DotenvStrictParseOutput` types and updated naming conventions
17 changes: 11 additions & 6 deletions packages/dotenv-strict/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@ import {
DotenvParseOutput,
} from 'dotenv'

type DotenvStrictConfigOptions<T extends ReadonlyArray<string>> =
type AnyEnvironmentVariable = string & {}
type StrictEnvironmentVariables = ReadonlyArray<string>

type DotenvStrictConfigOptions<T extends StrictEnvironmentVariables> =
DotenvConfigOptions & {
strict?: T
}

type DotenvStrictParseOutput<T extends ReadonlyArray<string>> = {
[K in T[number] | (string & {})]: string
type DotenvStrictParseOutput<T extends StrictEnvironmentVariables> = {
[EnvironmentVariable in T[number]]: string
} & {
[EnvironmentVariable in AnyEnvironmentVariable]: string | undefined
}

type DotenvStrictConfigOutput<T extends ReadonlyArray<string>> = Omit<
type DotenvStrictConfigOutput<T extends StrictEnvironmentVariables> = Omit<
DotenvConfigOutput,
'parsed'
> &
T extends ReadonlyArray<string>
T extends StrictEnvironmentVariables
? { parsed: DotenvStrictParseOutput<T> }
: { parsed?: DotenvParseOutput }

Expand All @@ -35,7 +40,7 @@ type DotenvStrictConfigOutput<T extends ReadonlyArray<string>> = Omit<
* env.parsed //=> {FOO: 'foo', BAR: 'bar'}
* ```
*/
export function config<T extends ReadonlyArray<string>>(
export function config<T extends StrictEnvironmentVariables>(
options?: DotenvStrictConfigOptions<T>,
): DotenvStrictConfigOutput<T> {
const { strict, ...restOptions } = options ?? {}
Expand Down

3 comments on commit d1d5a52

@vercel
Copy link

@vercel vercel bot commented on d1d5a52 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

aacc-next-ts – ./recipes/next-ts

aacc-next-ts-aaronccasanova.vercel.app
aacc-next-ts-git-main-aaronccasanova.vercel.app
aacc-next-ts.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d1d5a52 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

aacc-next-ts-styled-comps – ./recipes/next-ts-styled-comps

aacc-next-ts-styled-comps-git-main-aaronccasanova.vercel.app
aacc-next-ts-styled-comps-aaronccasanova.vercel.app
aacc-next-ts-styled-comps.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d1d5a52 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

aacc-scales – ./apps/scales

aacc-scales-git-main-aaronccasanova.vercel.app
aacc-scales.vercel.app
aacc-scales-aaronccasanova.vercel.app

Please sign in to comment.