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

Empty extends array introduces type error TS2339 #179

Open
rydkvist opened this issue Jan 31, 2024 · 3 comments
Open

Empty extends array introduces type error TS2339 #179

rydkvist opened this issue Jan 31, 2024 · 3 comments
Labels
bug - p0 bug with very low priority and is unlikely to cause issues

Comments

@rydkvist
Copy link

Background

Hi there! I'm having the following compile error TS2339 when I keep the extends key as an empty array.

The workaround I've found is simply removing the extends key, which of course makes sense if I'm not using it. But I wasn't expecting it to introduce compile errors for the environment variables for keeping the extends key around, for perhaps future use of it.

image

My environment config

const env = createEnv({
  client: {
    ...
  },
  server: {
    APP_ENV: z.string(),
    APP_NAME: z.string().min(1),
    ...
  },
  shared: {
    NODE_ENV: z.enum(['development', 'production']),
  },
  runtimeEnv: {
    APP_ENV: process.env.APP_ENV,
    APP_NAME: process.env.APP_NAME,
    ...
  },
  extends: [],
});

Relevant Package Versions

  • t3-env pkg v0.8.0
  • Next.js pkg v13.4.19
  • TypeScript pkgv5.2.2

Project tsconfig settings:

{
  "compilerOptions": {
    "target": "ES2020",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "preserveConstEnums": true,
    "declaration": false,
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@env": ["./env.ts"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}
@juliusmarminge
Copy link
Member

don't see a real issue here since you can just remove the empty array if you're not extending anything. obviously open for a fix if anyone wants to spend time on it but i probably wont fix it myself tbh...

@juliusmarminge juliusmarminge added bug Something isn't working bug - p0 bug with very low priority and is unlikely to cause issues and removed bug Something isn't working labels Feb 8, 2024
@OrJDev
Copy link

OrJDev commented Aug 28, 2024

don't see a real issue here since you can just remove the empty array if you're not extending anything. obviously open for a fix if anyone wants to spend time on it but i probably wont fix it myself tbh...

looks like extends is just broken, not only for empty arrays but:

import { createEnv } from "@t3-oss/env-nextjs";
import { vercel } from "@t3-oss/env-nextjs/presets";
import { z } from "zod";

// env is never
export const env = createEnv({
  extends: [vercel()],
  shared: {
    NODE_ENV: z
      .enum(["development", "production", "test"])
      .default("development"),
  },
  /**
   * Specify your server-side environment variables schema here.
   * This way you can ensure the app isn't built with invalid env vars.
   */
  server: {
    DATABASE_URL: z
      .string()
      .url()
      .refine(
        (str) => !str.includes("YOUR_MYSQL_URL_HERE"),
        "You forgot to change the default URL",
      ),

    UPSTASH_REDIS_REST_TOKEN: z.string(),
    UPSTASH_REDIS_REST_URL: z.string(),
    TELEGRAM_TOKEN: z.string(),
  },

  /**
   * Specify your client-side environment variables schema here.
   * For them to be exposed to the client, prefix them with `NEXT_PUBLIC_`.
   */
  client: {
    // NEXT_PUBLIC_CLIENTVAR: z.string(),
    NEXT_PUBLIC_TEST_IP: z.string().optional(),
  },
  /**
   * Destructure all variables from `process.env` to make sure they aren't tree-shaken away.
   */
  runtimeEnv: {
    DATABASE_URL: process.env.DATABASE_URL,
    NODE_ENV: process.env.NODE_ENV,
    NEXT_PUBLIC_TEST_IP: process.env.NEXT_PUBLIC_TEST_IP,
    UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN,
    UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL,
    TELEGRAM_TOKEN: process.env.TELEGRAM_TOKEN,

    // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
  },
  skipValidation:
    !!process.env.CI || process.env.npm_lifecycle_event === "lint",
});

@OrJDev
Copy link

OrJDev commented Aug 28, 2024

if i remove extends:

Screenshot 2024-08-28 at 22 48 26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - p0 bug with very low priority and is unlikely to cause issues
Projects
None yet
Development

No branches or pull requests

3 participants