Skip to content

Commit 2a84a45

Browse files
committed
revert: use @Noerrors + @ts-expect-error for strict layout twoslash
declare module triggers V8 segfaults in Twoslash's sandboxed compiler. Revert to the stable approach: @Noerrors suppresses the unresolvable path alias error, and @ts-expect-error annotates the intentional type error with a descriptive comment.
1 parent e13307f commit 2a84a45

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

apps/www/content/docs/nextjs/layouts/strict.mdx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,20 +278,30 @@ Import `env` from the client file (`env/client.ts`). The boundary protection wor
278278
1. **TypeScript Type Safety**: If you import `env` from the client file and try to access a server-side variable (like `DATABASE_URL`), you will get a TypeScript compilation error because it is not defined in the client-safe schema:
279279

280280
```ts title="src/app/client-component.ts" twoslash
281-
// @errors: 2339
282-
// @filename: nextjs-env.d.ts
283-
declare module "@/env/client" {
284-
export const env: {
285-
NEXT_PUBLIC_API_URL: string;
286-
NODE_ENV: "development" | "production" | "test";
287-
};
288-
}
281+
// @noErrors
282+
// @filename: /env/internal/shared.ts
283+
import { type } from "@arkenv/nextjs/shared";
284+
/**
285+
* @internal 🛑 INTERNAL SCHEMA ONLY.
286+
* Do not import this directly. Import `env` from `./client` or `./server` instead.
287+
*/
288+
export const SharedSchema = type({ NODE_ENV: "'development' | 'production' | 'test'" });
289+
290+
// @filename: /env/client.ts
291+
import arkenv from "@arkenv/nextjs/client";
292+
import { SharedSchema } from "./internal/shared";
293+
export const env = arkenv(
294+
{ NEXT_PUBLIC_API_URL: "string" },
295+
{ extends: [SharedSchema], runtimeEnv: { NEXT_PUBLIC_API_URL: "https://api.example.com", NODE_ENV: "development" } }
296+
);
297+
289298
// @filename: /client-component.ts
290299
// ---cut---
291300
import { env } from "@/env/client";
292301

293302
export function ClientComponent() {
294303
const api = env.NEXT_PUBLIC_API_URL;
304+
// @ts-expect-error DATABASE_URL is not defined in client env
295305
const db = env.DATABASE_URL;
296306

297307
return `API URL: ${api}`;

apps/www/content/docs/nuxt/layouts/strict.mdx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,25 @@ Import `env` from the client file (`env/client.ts`). The boundary protection wor
236236
1. **TypeScript type safety**: If you import `env` from the client file and try to access a server-side variable (like `DATABASE_URL`), you will get a TypeScript compilation error because it is not defined in the client-safe schema:
237237

238238
```ts title="pages/index.ts" twoslash
239-
// @errors: 2339
240-
// @filename: nuxt-env.d.ts
241-
declare module "~~/env/client" {
242-
export const env: {
243-
NUXT_PUBLIC_API_URL: string;
244-
NODE_ENV: "development" | "production" | "test";
245-
};
246-
}
239+
// @noErrors
240+
// @filename: env/internal/shared.ts
241+
import { type } from "@arkenv/nuxt/shared";
242+
export const SharedSchema = type({
243+
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
244+
});
245+
// @filename: env/client.ts
246+
import arkenv from "@arkenv/nuxt/client";
247+
import { SharedSchema } from "./internal/shared";
248+
export const env = arkenv(
249+
{ NUXT_PUBLIC_API_URL: "string = 'https://api.example.com'" },
250+
{ extends: [SharedSchema] },
251+
);
247252
// @filename: pages/index.ts
248253
// ---cut---
249254
import { env } from "~~/env/client";
250255

251256
const api = env.NUXT_PUBLIC_API_URL;
257+
// @ts-expect-error DATABASE_URL is not defined in client env
252258
const db = env.DATABASE_URL;
253259
```
254260

0 commit comments

Comments
 (0)