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: remove ts-ignores on env.mjs #1189

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/gold-berries-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

fix: remove ts-ignores on env.mjs
23 changes: 12 additions & 11 deletions cli/template/base/src/env.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { z } from "zod";

/**
Expand Down Expand Up @@ -32,16 +31,21 @@ const processEnv = {
// --------------------------

const merged = server.merge(client);
/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
let env = process.env;

/** @typedef {z.input<typeof merged>} MergedInput */
/** @typedef {z.infer<typeof merged>} MergedOutput */
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */

let env = /** @type {MergedOutput} */ (process.env);

if (!!process.env.SKIP_ENV_VALIDATION == false) {
const isServer = typeof window === "undefined";

const parsed = isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
const parsed = /** @type {MergedSafeParseReturn} */ (
isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
);
juliusmarminge marked this conversation as resolved.
Show resolved Hide resolved

if (parsed.success === false) {
console.error(
Expand All @@ -51,8 +55,6 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
throw new Error("Invalid environment variables");
}

/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
env = new Proxy(parsed.data, {
get(target, prop) {
if (typeof prop !== "string") return undefined;
Expand All @@ -64,8 +66,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
? "❌ Attempted to access a server-side environment variable on the client"
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
);
/* @ts-ignore - can't type this properly in jsdoc */
return target[prop];
return target[/** @type {keyof typeof target} */ (prop)];
},
});
}
Expand Down
23 changes: 12 additions & 11 deletions cli/template/extras/src/env/with-auth-prisma.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { z } from "zod";

/**
Expand Down Expand Up @@ -52,16 +51,21 @@ const processEnv = {
// --------------------------

const merged = server.merge(client);
/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
let env = process.env;

/** @typedef {z.input<typeof merged>} MergedInput */
/** @typedef {z.infer<typeof merged>} MergedOutput */
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */

let env = /** @type {MergedOutput} */ (process.env);

if (!!process.env.SKIP_ENV_VALIDATION == false) {
const isServer = typeof window === "undefined";

const parsed = isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
const parsed = /** @type {MergedSafeParseReturn} */ (
isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
);

if (parsed.success === false) {
console.error(
Expand All @@ -71,8 +75,6 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
throw new Error("Invalid environment variables");
}

/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
env = new Proxy(parsed.data, {
get(target, prop) {
if (typeof prop !== "string") return undefined;
Expand All @@ -84,8 +86,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
? "❌ Attempted to access a server-side environment variable on the client"
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
);
/* @ts-ignore - can't type this properly in jsdoc */
return target[prop];
return target[/** @type {keyof typeof target} */ (prop)];
},
});
}
Expand Down
23 changes: 12 additions & 11 deletions cli/template/extras/src/env/with-auth.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { z } from "zod";

/**
Expand Down Expand Up @@ -50,16 +49,21 @@ const processEnv = {
// --------------------------

const merged = server.merge(client);
/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
let env = process.env;

/** @typedef {z.input<typeof merged>} MergedInput */
/** @typedef {z.infer<typeof merged>} MergedOutput */
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */

let env = /** @type {MergedOutput} */ (process.env);

if (!!process.env.SKIP_ENV_VALIDATION == false) {
const isServer = typeof window === "undefined";

const parsed = isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
const parsed = /** @type {MergedSafeParseReturn} */ (
isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
);

if (parsed.success === false) {
console.error(
Expand All @@ -69,8 +73,6 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
throw new Error("Invalid environment variables");
}

/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
env = new Proxy(parsed.data, {
get(target, prop) {
if (typeof prop !== "string") return undefined;
Expand All @@ -82,8 +84,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
? "❌ Attempted to access a server-side environment variable on the client"
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
);
/* @ts-ignore - can't type this properly in jsdoc */
return target[prop];
return target[/** @type {keyof typeof target} */ (prop)];
},
});
}
Expand Down
23 changes: 12 additions & 11 deletions cli/template/extras/src/env/with-prisma.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { z } from "zod";

/**
Expand Down Expand Up @@ -34,16 +33,21 @@ const processEnv = {
// --------------------------

const merged = server.merge(client);
/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
let env = process.env;

/** @typedef {z.input<typeof merged>} MergedInput */
/** @typedef {z.infer<typeof merged>} MergedOutput */
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */

let env = /** @type {MergedOutput} */ (process.env);

if (!!process.env.SKIP_ENV_VALIDATION == false) {
const isServer = typeof window === "undefined";

const parsed = isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
const parsed = /** @type {MergedSafeParseReturn} */ (
isServer
? merged.safeParse(processEnv) // on server we can validate all env vars
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
);

if (parsed.success === false) {
console.error(
Expand All @@ -53,8 +57,6 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
throw new Error("Invalid environment variables");
}

/** @type z.infer<merged>
* @ts-ignore - can't type this properly in jsdoc */
env = new Proxy(parsed.data, {
get(target, prop) {
if (typeof prop !== "string") return undefined;
Expand All @@ -66,8 +68,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
? "❌ Attempted to access a server-side environment variable on the client"
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
);
/* @ts-ignore - can't type this properly in jsdoc */
return target[prop];
return target[/** @type {keyof typeof target} */ (prop)];
},
});
}
Expand Down