Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle empty env object type #21

Merged
merged 8 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export interface StrictOptions<

export function createEnv<
TPrefix extends string,
TServer extends Record<string, ZodType>,
TClient extends Record<string, ZodType>
TServer extends Record<string, ZodType> = NonNullable<unknown>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is my first time using NonNullable<unknown>, an alternative to {}, as the ESLint rule doesn't allow me to use it🤷

Copy link
Member

Choose a reason for hiding this comment

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

Record<string, never> is the type for {} that eslint allows fyi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was using that originally, but unfortunately it didn't work in this case.

TClient extends Record<string, ZodType> = NonNullable<unknown>
>(
opts:
| LooseOptions<TPrefix, TServer, TClient>
Expand Down
14 changes: 10 additions & 4 deletions packages/nextjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ const CLIENT_PREFIX = "NEXT_PUBLIC_" as const;
type ClientPrefix = typeof CLIENT_PREFIX;

interface Options<
TServer extends Record<string, ZodType>,
TClient extends Record<`${ClientPrefix}${string}`, ZodType>
TServer extends Record<string, ZodType> = NonNullable<unknown>,
TClient extends Record<
`${ClientPrefix}${string}`,
ZodType
> = NonNullable<unknown>
juliusmarminge marked this conversation as resolved.
Show resolved Hide resolved
> extends Omit<
StrictOptions<ClientPrefix, TServer, TClient>,
"runtimeEnvStrict" | "runtimeEnv" | "clientPrefix"
Expand All @@ -19,8 +22,11 @@ interface Options<
}

export function createEnv<
TServer extends Record<string, ZodType>,
TClient extends Record<`${ClientPrefix}${string}`, ZodType>
TServer extends Record<string, ZodType> = NonNullable<unknown>,
TClient extends Record<
`${ClientPrefix}${string}`,
ZodType
> = NonNullable<unknown>
>({ runtimeEnv, ...opts }: Options<TServer, TClient>) {
return createEnvCore<ClientPrefix, TServer, TClient>({
...opts,
Expand Down