Skip to content

Commit bf12635

Browse files
fix: remove ts-ignores on env.mjs (#1189)
* fix: remove ts-ignores on env.mjs * Fix ts-ignores in all other env.mjs * Create gold-berries-happen.md --------- Co-authored-by: Julius Marminge <[email protected]>
1 parent 69eabee commit bf12635

File tree

5 files changed

+53
-44
lines changed

5 files changed

+53
-44
lines changed

Diff for: .changeset/gold-berries-happen.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-t3-app": patch
3+
---
4+
5+
fix: remove ts-ignores on env.mjs

Diff for: cli/template/base/src/env.mjs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment */
21
import { z } from "zod";
32

43
/**
@@ -32,16 +31,21 @@ const processEnv = {
3231
// --------------------------
3332

3433
const merged = server.merge(client);
35-
/** @type z.infer<merged>
36-
* @ts-ignore - can't type this properly in jsdoc */
37-
let env = process.env;
34+
35+
/** @typedef {z.input<typeof merged>} MergedInput */
36+
/** @typedef {z.infer<typeof merged>} MergedOutput */
37+
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */
38+
39+
let env = /** @type {MergedOutput} */ (process.env);
3840

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

42-
const parsed = isServer
43-
? merged.safeParse(processEnv) // on server we can validate all env vars
44-
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
44+
const parsed = /** @type {MergedSafeParseReturn} */ (
45+
isServer
46+
? merged.safeParse(processEnv) // on server we can validate all env vars
47+
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
48+
);
4549

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

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

Diff for: cli/template/extras/src/env/with-auth-prisma.mjs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment */
21
import { z } from "zod";
32

43
/**
@@ -52,16 +51,21 @@ const processEnv = {
5251
// --------------------------
5352

5453
const merged = server.merge(client);
55-
/** @type z.infer<merged>
56-
* @ts-ignore - can't type this properly in jsdoc */
57-
let env = process.env;
54+
55+
/** @typedef {z.input<typeof merged>} MergedInput */
56+
/** @typedef {z.infer<typeof merged>} MergedOutput */
57+
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */
58+
59+
let env = /** @type {MergedOutput} */ (process.env);
5860

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

62-
const parsed = isServer
63-
? merged.safeParse(processEnv) // on server we can validate all env vars
64-
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
64+
const parsed = /** @type {MergedSafeParseReturn} */ (
65+
isServer
66+
? merged.safeParse(processEnv) // on server we can validate all env vars
67+
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
68+
);
6569

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

74-
/** @type z.infer<merged>
75-
* @ts-ignore - can't type this properly in jsdoc */
7678
env = new Proxy(parsed.data, {
7779
get(target, prop) {
7880
if (typeof prop !== "string") return undefined;
@@ -84,8 +86,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
8486
? "❌ Attempted to access a server-side environment variable on the client"
8587
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
8688
);
87-
/* @ts-ignore - can't type this properly in jsdoc */
88-
return target[prop];
89+
return target[/** @type {keyof typeof target} */ (prop)];
8990
},
9091
});
9192
}

Diff for: cli/template/extras/src/env/with-auth.mjs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment */
21
import { z } from "zod";
32

43
/**
@@ -50,16 +49,21 @@ const processEnv = {
5049
// --------------------------
5150

5251
const merged = server.merge(client);
53-
/** @type z.infer<merged>
54-
* @ts-ignore - can't type this properly in jsdoc */
55-
let env = process.env;
52+
53+
/** @typedef {z.input<typeof merged>} MergedInput */
54+
/** @typedef {z.infer<typeof merged>} MergedOutput */
55+
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */
56+
57+
let env = /** @type {MergedOutput} */ (process.env);
5658

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

60-
const parsed = isServer
61-
? merged.safeParse(processEnv) // on server we can validate all env vars
62-
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
62+
const parsed = /** @type {MergedSafeParseReturn} */ (
63+
isServer
64+
? merged.safeParse(processEnv) // on server we can validate all env vars
65+
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
66+
);
6367

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

72-
/** @type z.infer<merged>
73-
* @ts-ignore - can't type this properly in jsdoc */
7476
env = new Proxy(parsed.data, {
7577
get(target, prop) {
7678
if (typeof prop !== "string") return undefined;
@@ -82,8 +84,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
8284
? "❌ Attempted to access a server-side environment variable on the client"
8385
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
8486
);
85-
/* @ts-ignore - can't type this properly in jsdoc */
86-
return target[prop];
87+
return target[/** @type {keyof typeof target} */ (prop)];
8788
},
8889
});
8990
}

Diff for: cli/template/extras/src/env/with-prisma.mjs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment */
21
import { z } from "zod";
32

43
/**
@@ -34,16 +33,21 @@ const processEnv = {
3433
// --------------------------
3534

3635
const merged = server.merge(client);
37-
/** @type z.infer<merged>
38-
* @ts-ignore - can't type this properly in jsdoc */
39-
let env = process.env;
36+
37+
/** @typedef {z.input<typeof merged>} MergedInput */
38+
/** @typedef {z.infer<typeof merged>} MergedOutput */
39+
/** @typedef {z.SafeParseReturnType<MergedInput, MergedOutput>} MergedSafeParseReturn */
40+
41+
let env = /** @type {MergedOutput} */ (process.env);
4042

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

44-
const parsed = isServer
45-
? merged.safeParse(processEnv) // on server we can validate all env vars
46-
: client.safeParse(processEnv); // on client we can only validate the ones that are exposed
46+
const parsed = /** @type {MergedSafeParseReturn} */ (
47+
isServer
48+
? merged.safeParse(processEnv) // on server we can validate all env vars
49+
: client.safeParse(processEnv) // on client we can only validate the ones that are exposed
50+
);
4751

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

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

0 commit comments

Comments
 (0)