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

Unsure on ArkType implementation / maybe an issue #320

Open
hexcowboy opened this issue Feb 13, 2025 · 4 comments
Open

Unsure on ArkType implementation / maybe an issue #320

hexcowboy opened this issue Feb 13, 2025 · 4 comments

Comments

@hexcowboy
Copy link

I'm trying to use Standard Schema from ArkType but I'm not getting proper types here.

import { type } from "arktype";

import { createEnv } from "@t3-oss/env-core";

export const env = createEnv({
  server: {
    DATABASE_URL: type(/^postgres:\/\/.+/),
    GOOGLE_CLIENT_ID: type(/^.*.apps.googleusercontent.com$/),
    GOOGLE_CLIENT_SECRET: type("string == 35"),
  },
  clientPrefix: "NEXT_PUBLIC_",
  runtimeEnv: process.env,
  emptyStringAsUndefined: true,
});

typeof env
// const env: Readonly<{
//   [x: string]: unknown;
// }>
"@t3-oss/env-core": "^0.12.0",
"arktype": "^2.0.4"
@hexcowboy
Copy link
Author

Also tried the following:

server: type({
  DATABASE_URL: /^postgres:\/\/.+/,
  GOOGLE_CLIENT_ID: /^.*.apps.googleusercontent.com$/,
  GOOGLE_CLIENT_SECRET: "string == 35",
})['~standard'],
// Type 'ArkTypeProps<{ DATABASE_URL: string; GOOGLE_CLIENT_ID: string; GOOGLE_CLIENT_SECRET: string; }, { DATABASE_URL: string; GOOGLE_CLIENT_ID: string; GOOGLE_CLIENT_SECRET: string; }>' is not assignable to type 'Partial<{ [x: string]: StandardSchemaV1<unknown, unknown>; }>'.
//   Index signature for type 'string' is missing in type 'ArkTypeProps<{ DATABASE_URL: string; GOOGLE_CLIENT_ID: string; GOOGLE_CLIENT_SECRET: string; }, { DATABASE_URL: string; GOOGLE_CLIENT_ID: string; GOOGLE_CLIENT_SECRET: string; }>'.
// Related information:
//   * index.d.ts#165,5: The expected type comes from property 'server' which is declared here on type 'EnvOptions<"NEXT_PUBLIC_", TServerFormat, {}, {}, []>'
DATABASE_URL: type(/^postgres:\/\/.+/)["~standard"],
// Property '"~standard"' is missing in type 'ArkTypeProps<string, string>' but required in type 'StandardSchemaV1<unknown, unknown>'.
// Related information:
//   * index.d.ts#4,14: '"~standard"' is declared here.

@juliusmarminge
Copy link
Member

Interesting... never used arktype. This works, wonder why it doesn't when it's inline 🤔

Image

@juliusmarminge
Copy link
Member

Hey @ssalbdivad - do you have any ideas?

@ssalbdivad
Copy link

@juliusmarminge This may be due to some issues in TS with how the outer context of a function can affect nested inference.

I'm making some changes to try and work around this in 2.1.0 that will hopefully avoid the issues inlining the type call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants