Skip to content

Commit

Permalink
fix: shared envs aren't typechecked in runtimeEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
goszczynskip committed Jul 18, 2023
1 parent 2bb4d0a commit 7e751a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ type EnvReturn<

type RuntimeOptions<
TPrefix extends string,
TShared extends Record<string, ZodType>,
TClient extends Record<string, ZodType>,
TServer extends Record<string, ZodType>
> = {
runtimeEnv: Record<
| keyof TShared
| {
[TKey in keyof TClient]: TKey extends `${TPrefix}${string}`
? TKey
Expand Down Expand Up @@ -349,7 +351,7 @@ type EnvOptions<
Impossible<TransformOptions<never, never, never>> &
Impossible<FeatureFlagsOptions<never, never, never, never, never>>)
) &
RuntimeOptions<TPrefix, TClient, TServer> &
RuntimeOptions<TPrefix, TShared, TClient, TServer> &
CommonOptions<TShared>;

export function createEnv<
Expand Down
20 changes: 20 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ describe("createEnv", () => {
});

describe.skip("types", () => {
it("should fail when runtimeEnv doesn't contain shared keys", () => {
createEnv({
isServer: true,
clientPrefix: "PREFIX_" as const,
client: {
PREFIX_TEST: z.string(),
},
shared: {
SUT: z.string(),
},
server: {
TEST: z.string(),
},
// @ts-expect-error
runtimeEnv: {
PREFIX_TEST: "",
},
});
});

it("Should fail when server env contain client prefixed env", () => {
createEnv({
isServer: true,
Expand Down

0 comments on commit 7e751a9

Please sign in to comment.