Skip to content

Coercion: Fix manual morphs (pipes) #592

Description

@yamcodes

This type doesn't work when being put into createEnv:

export const Env = type({
	PORT: "number.port",
	VITE_MY_VAR: "string",
	VITE_MY_NUMBER: "number",
	VITE_MY_BOOLEAN: "boolean",
	VITE_MY_NUMBER_MANUAL: type("string").pipe((str) => Number.parseInt(str, 10)),
	VITE_MY_BOOLEAN_MANUAL: type("string").pipe((str) => str === "true"),
});

The existence of either of those last two types throws:

apps/playgrounds/vite on  coercion [$!⇣] via 🤖 v24.11.1 
❯ nb

> vite-playground@0.0.0 build /Users/yamcodes/code/arkenv/apps/playgrounds/vite
> tsc -b && vite build

failed to load config from /Users/yamcodes/code/arkenv/apps/playgrounds/vite/vite.config.ts
error during build:
ToJsonSchemaError: {
    code: "morph",
    base: {
        type: "string"
    },
    out: null
}
    at Object.throw (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/shared/toJsonSchema.js:36:15)
    at Object.morph (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/shared/toJsonSchema.js:24:41)
    at MorphNode.innerToJsonSchema (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/roots/morph.js:120:29)
    at MorphNode.toResolvedJsonSchema (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/roots/root.js:102:29)
    at MorphNode.toJsonSchemaRecurse (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/roots/root.js:94:21)
    at StructureNode.reduceObjectJsonSchema (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/structure/structure.js:560:48)
    at StructureNode.reduceJsonSchema (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/structure/structure.js:541:29)
    at file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/roots/intersection.js:179:21
    at Array.reduce (<anonymous>)
    at IntersectionNode.innerToJsonSchema (file:///Users/yamcodes/code/arkenv/node_modules/.pnpm/@ark+schema@0.56.0/node_modules/@ark/schema/out/roots/intersection.js:175:30)
 ELIFECYCLE  Command failed with exit code 1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arkenvChanges to the `arkenv` npm package.bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions