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

fix: preserve morphs on some piped properties #1174

Merged
merged 3 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ark/attest/tsVersioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const forTypeScriptVersions = (
const nodeModules = join(assertPackageRoot(process.cwd()), "node_modules")
const tsPrimaryPath = join(nodeModules, "typescript")
const tsTemporaryPath = join(nodeModules, "typescript-temp")
if (existsSync(tsTemporaryPath)) unlinkSync(tsTemporaryPath)
if (existsSync(tsPrimaryPath)) renameSync(tsPrimaryPath, tsTemporaryPath)

try {
Expand All @@ -41,7 +42,7 @@ export const forTypeScriptVersions = (
try {
if (existsSync(tsPrimaryPath)) unlinkSync(tsPrimaryPath)

symlinkSync(targetPath, tsPrimaryPath)
symlinkSync(targetPath, tsPrimaryPath, "junction")
fn(version)
passedVersions.push(version)
} catch (e) {
Expand All @@ -65,6 +66,7 @@ export const forTypeScriptVersions = (
} finally {
if (existsSync(tsTemporaryPath)) {
console.log(`⏮️ Restoring your original TypeScript version...`)
unlinkSync(tsPrimaryPath)
renameSync(tsTemporaryPath, tsPrimaryPath)
}
}
Expand Down
6 changes: 3 additions & 3 deletions ark/repo/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { symlinkSync } from "fs"
import { copyFileSync } from "fs"
import { join } from "path"
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { fromCwd, fromHere, rmRf, shell, writeJson } from "../fs/index.ts"
Expand All @@ -15,10 +15,10 @@ const buildCurrentProject = () =>
try {
rmRf(outDir)
rmRf("tsconfig.build.json")
symlinkSync(`../repo/tsconfig.${buildKind}.json`, "tsconfig.build.json")
copyFileSync(`../repo/tsconfig.${buildKind}.json`, "tsconfig.build.json")
buildCurrentProject()
rmRf("tsconfig.build.json")
symlinkSync(`../repo/tsconfig.dts.json`, "tsconfig.build.json")
copyFileSync(`../repo/tsconfig.dts.json`, "tsconfig.build.json")
buildCurrentProject()
if (buildKind === "cjs")
writeJson(join(outDir, "package.json"), { type: "commonjs" })
Expand Down
24 changes: 12 additions & 12 deletions ark/repo/scratch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { type } from "arktype"

const AorB = type({
"+": "reject",
something: "'A'"
}).or({
"+": "reject",
something: "'B'",
somethingelse: "number"
})

console.log(AorB.internal.assertHasKind("union").discriminantJson)

const out2 = AorB({ something: "A" }) //?
console.log(
type({
foo: type("string").pipe(() => 123)
})
.pipe(c => c)
.to({
foo: "123"
})({
foo: "bar"
}) + ""
)
// foo must be 123 (was "bar")
2 changes: 1 addition & 1 deletion ark/schema/shared/intersections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const _pipeMorphed = (

return ctx.$.node("morph", {
morphs,
in: from.in
in: from.inner.in as any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would usually use as never in a case like this but I can update that later, it's pretty inconsequential.

Copy link
Contributor Author

@Dimava Dimava Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the types anyway, there's a good chance it shouldn't need the case at all

})
}

Comment on lines 201 to 207
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used as any but maybe it should be typed better

Expand Down
11 changes: 11 additions & 0 deletions ark/type/__tests__/pipe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,4 +888,15 @@ Right: { foo: (In: string) => Out<{ [string]: $jsonObject | number | string | $j

attest(appendSeparatedLengths("a")).snap("a12|45")
})

it("doesn't lose input prop morphs", () => {
const T = type({
foo: type("string").pipe(s => s.length)
})
.pipe(o => o)
.to({
foo: "number"
})
attest(T({ foo: "bar" })).snap({ foo: 3 })
})
})