Support type definitions created with type() in createEnv#382
Conversation
- Add support for accepting type definitions created with ArkType's type() function - Maintain backward compatibility with raw schema objects - Implement InferType helper to extract types from type definitions - Update vite plugin to also accept type definitions - Full type inference works when using type definitions Closes #381
|
WalkthroughAdds support for passing ArkType Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant arkenv/createEnv as createEnv
participant Runtime as RuntimeDetection
participant TypeDef as "type() definition"
participant Raw as "raw schema object"
Note over createEnv,Runtime: New runtime branch detection (checks for `assert`)
User->>createEnv: call createEnv(def, env?)
createEnv->>Runtime: inspect def (has assert?)
alt def has assert (type.Any)
Runtime->>TypeDef: treat as type definition -> use assert() to validate
TypeDef-->>createEnv: validated/typed env
else def is raw schema
Runtime->>Raw: convert via $.type.raw(def) -> validate
Raw-->>createEnv: validated/typed env
end
createEnv-->>User: return validated environment object
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
type() in createEnvtype() in createEnv
commit: |
📦 Bundle Size Report✅ All size limits passed! |
…s with type definitions
…tions - Added a new example for `env2` using a custom environment object with HOST, PORT, and DEBUG properties. - Included type inference examples for both production and test environments to demonstrate consistent type structure.
- Added overloads to createEnv to support both EnvSchema and type.Any, improving type inference. - Updated Vite plugin to utilize the new createEnv overloads, ensuring better type precision for environment configurations.
- Commented out the Banner component in layout.tsx for potential future use. - Updated meta.json to reflect a new link format for reusing schemas. - Revised morphs.mdx to remove the icon and clarify the description. - Enhanced how-to/reuse-schemas.mdx documentation with improved titles, descriptions, and examples for better clarity on schema reuse and type definitions.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
apps/www/app/layout.tsx (1)
1-1: Consider removing Banner code if the feature is long-term disabledCommenting out the Banner import and JSX is fine short term, but if this banner is not coming back soon, consider deleting the commented code to reduce noise in the layout.
Also applies to: 51-62
apps/www/content/docs/how-to/reuse-schemas.mdx (2)
13-22: Clean up unusedtypeimport in the basic usage snippetIn the “Basic usage” example you import
typefrom"arktype"but never use it; the snippet only shows a raw schema object. Either remove the import or update the example to demonstratetype()usage so it matches the surrounding explanation.
24-29: Add links to concrete runtime examples for reuse scenariosSince this section calls out Vite, Next.js, and Bun as common multi-runtime setups, it would be helpful to link directly to the existing examples (Node.js, Bun, Vite) so readers can see full working configs alongside this pattern.
Based on learnings
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/www/app/layout.tsx(3 hunks)apps/www/content/docs/how-to/reuse-schemas.mdx(1 hunks)apps/www/content/docs/meta.json(1 hunks)apps/www/content/docs/morphs.mdx(0 hunks)packages/arkenv/src/create-env.ts(1 hunks)packages/vite-plugin/src/index.ts(2 hunks)
💤 Files with no reviewable changes (1)
- apps/www/content/docs/morphs.mdx
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: yamcodes
Repo: yamcodes/arkenv PR: 132
File: packages/arkenv/README.md:13-14
Timestamp: 2025-09-09T17:37:19.650Z
Learning: For yamcodes/arkenv project: Runtime support documentation should link to specific examples: Node.js (examples/basic), Bun (examples/with-bun), Vite (examples/with-vite-react-ts).
🧬 Code graph analysis (3)
apps/www/content/docs/how-to/reuse-schemas.mdx (3)
packages/arkenv/src/type.test.ts (6)
envType(29-47)envType(202-217)envType(5-9)it(4-218)envType(86-108)envType(171-190)packages/arkenv/src/index.test.ts (2)
vi(65-81)vi(25-35)packages/arkenv/src/custom-types.integration.test.ts (1)
env(191-197)
packages/vite-plugin/src/index.ts (3)
packages/arkenv/src/type.ts (1)
type(3-3)packages/arkenv/src/create-env.ts (1)
EnvSchema(7-7)packages/arkenv/src/type.test.ts (8)
envType(11-15)envType(118-118)envType(127-127)envType(29-47)envType(202-217)envType(86-108)envType(5-9)envType(171-190)
packages/arkenv/src/create-env.ts (4)
packages/arkenv/src/type.ts (1)
type(3-3)packages/arkenv/src/scope.ts (1)
$(9-19)packages/arkenv/src/type.test.ts (8)
envType(29-47)envType(86-108)envType(202-217)envType(127-127)envType(11-15)envType(118-118)envType(5-9)envType(171-190)packages/arkenv/src/custom-types.integration.test.ts (1)
env(191-197)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test-e2e (e2e)
- GitHub Check: test-e2e (a11y)
🔇 Additional comments (5)
apps/www/content/docs/meta.json (1)
13-14: New How-to nav entry looks consistentThe added “[New]Reuse your schema” entry (and its placement under the How-to section) matches the new doc slug and keeps the structure valid.
apps/www/content/docs/how-to/reuse-schemas.mdx (1)
141-164: Mixing raw schemas and type definitions is clearly illustratedThe “Mixing approaches” section does a good job showing one-off raw schemas alongside reusable
type()definitions, matching the new API capabilities and making the trade-offs clear.packages/vite-plugin/src/index.ts (1)
3-3: Overloads cleanly extend the plugin to accepttype()definitionsThe added
arkenv(options: type.Any): Pluginoverload and the combined implementation signature (EnvSchema<T> | type.Any) line up withcreateEnv’s new capabilities, and the type-only ArkType import keeps runtime unaffected. The comments about runtime behavior vs. overload precision are also helpful.Please double-check against the current ArkType typings that
type.Anyis the right surface here and thatimport type { type } from "arktype"correctly exposes theAnytype member in your TS version.Also applies to: 11-17, 21-23
packages/arkenv/src/create-env.ts (2)
9-21:InferType<T>correctly bridges ArkType definitions to value typesThe
InferType<T>conditional nicely handles both callable ArkType types (via the function signature) andtype.Any<…>directly, giving you the validated value type while excludingtype.errors. This is a good fit for mappingtype()definitions to the resulting env object shape.Given this relies on ArkType’s
type.Anyand callable type shape, please confirm against the current ArkType.d.tsthattype.Anystill matches these assumptions (call signature +<Value, Scope>generics).
35-50: Overloads and runtime detection look sound; union typing may be worth re-checkingThe overloads distinguish nicely between raw schemas (
EnvSchema<T>) andtype()definitions (type.Any), and the runtime check (typeof def === "function" && "assert" in def) should safely pick out top-level ArkType definitions without affecting existing object schemas (including those with nestedtype(...)values). The union overload usingEnvSchema<T> | type.AnyplusInferType<typeof def>should behave well for callers that accept both forms, especially in your Vite plugin use case.It would be good to re-run your TS type tests or a local
tsccheck focusing on mixed-schema call sites (wheredefis typed asEnvSchema<T> | type.Any) to ensure the union overload returns the expected inferred env type in practice.Also applies to: 51-56
…chema reuse - Changed the environment variable setup in index.ts to utilize a schema defined with type() for better type safety. - Updated how-to/reuse-schemas.mdx to clarify the benefits of sharing schemas across different environments and provided links to relevant examples.
- Updated tests in docs-navigation.test.ts to verify 'rel' attributes for GitHub and ArkType links using `getAttribute` and `toContain` for better clarity and accuracy. - Removed redundant attribute checks for 'rel' and streamlined the assertions for improved readability.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tooling/playwright-www/tests/docs-navigation.test.ts (1)
149-163: Order-independentrelchecks look good; consider a tiny DRY/helper improvementSwitching to substring checks for
"noopener"/"noreferrer"makes the test robust to attribute order and matches the intent better than exact-string assertions. The GitHub and ArkType blocks now share the same pattern; if you want to tighten things up later, you could factor this into a small helper (e.g.,assertSecureExternalLink(link)), or reuse the same approach in other external-link tests for consistency. Not blocking.apps/playgrounds/node/index.ts (1)
3-12: NewenvSchemapattern correctly demonstratestype()-based arkenv usageDefining
envSchemawithtype({...})(including theALLOWED_ORIGINSdefault) and then callingarkenv(envSchema, process.env)is a clear example of the new “reusable schema” flow and should exercise the updated overloads as intended. If you later want this playground to double as a reuse example for docs, you might also exportenvSchemaso it can be imported elsewhere, but the current setup is perfectly fine as-is.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/playgrounds/node/index.ts(1 hunks)apps/www/content/docs/how-to/reuse-schemas.mdx(1 hunks)tooling/playwright-www/tests/docs-navigation.test.ts(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- apps/www/content/docs/how-to/reuse-schemas.mdx
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: yamcodes
Repo: yamcodes/arkenv PR: 132
File: packages/arkenv/README.md:13-14
Timestamp: 2025-09-09T17:37:19.650Z
Learning: For yamcodes/arkenv project: Runtime support documentation should link to specific examples: Node.js (examples/basic), Bun (examples/with-bun), Vite (examples/with-vite-react-ts).
🧬 Code graph analysis (2)
tooling/playwright-www/tests/docs-navigation.test.ts (5)
apps/www/components/page/star-us-button.test.tsx (4)
link(20-24)link(48-51)render(16-25)render(42-52)tooling/playwright-www/tests/morphs.test.ts (1)
page(106-126)apps/www/components/page/edit-on-github.test.tsx (1)
mockGetLinkTitleAndHref(60-73)tooling/playwright-www/tests/integrations.test.ts (1)
pages(128-149)tooling/playwright-www/tests/homepage.test.ts (1)
page(55-92)
apps/playgrounds/node/index.ts (4)
packages/arkenv/src/type.ts (1)
type(3-3)packages/vite-plugin/src/index.ts (2)
arkenv(15-36)arkenv(10-29)packages/arkenv/src/index.test.ts (2)
arkenv(50-53)vi(65-81)packages/arkenv/src/create-env.ts (1)
createEnv(21-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test-e2e (a11y)
- GitHub Check: test-e2e (e2e)
Summary
This PR adds support for accepting type definitions created with ArkType's
type()function in addition to raw schema objects increateEnv()and the vite plugin.Changes
packages/arkenv/src/create-env.ts:InferType<T>helper to extract types from type definitionsassertmethod)packages/vite-plugin/src/index.ts:Benefits
type()can be shared across modulesExample Usage
Testing
Closes #381
Summary by CodeRabbit
New Features
Documentation
Other
✏️ Tip: You can customize this high-level summary in your review settings.