diff --git a/index.ts b/index.ts index 6f58a83..ee0fae1 100644 --- a/index.ts +++ b/index.ts @@ -201,10 +201,12 @@ type EnvReturn< type RuntimeOptions< TPrefix extends string, + TShared extends Record, TClient extends Record, TServer extends Record > = { runtimeEnv: Record< + | keyof TShared | { [TKey in keyof TClient]: TKey extends `${TPrefix}${string}` ? TKey @@ -349,7 +351,7 @@ type EnvOptions< Impossible> & Impossible>) ) & - RuntimeOptions & + RuntimeOptions & CommonOptions; export function createEnv< diff --git a/test/index.test.ts b/test/index.test.ts index c297b0a..9c16357 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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,