Skip to content

Commit

Permalink
fix: extracted morph inference
Browse files Browse the repository at this point in the history
  • Loading branch information
ssalbdivad committed Oct 23, 2023
1 parent f93eb12 commit 14d897d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions dev/configs/.changeset/heavy-melons-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"arktype": patch
---

Fix an issue causing some morphs to not be properly extracted when .infer(red)
4 changes: 4 additions & 0 deletions dev/test/morph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ describe("morph", () => {
]
])
})
it("union with output", () => {
const t = type("number|parsedNumber")
attest(t.infer).typed as number
})
it("double intersection", () => {
attest(() => {
scope({
Expand Down
8 changes: 6 additions & 2 deletions src/scopes/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ export type AnonymousTypeName = `λ${string}`
export const isAnonymousName = (name: string): name is AnonymousTypeName =>
name[0] === "λ"

export type asIn<t> = asIo<t, "in"> extends t ? t : asIo<t, "in">
export type asIn<t> = [t, asIo<t, "out">] extends [asIo<t, "out">, t]
? t
: asIo<t, "in">

export type asOut<t> = asIo<t, "out"> extends t ? t : asIo<t, "out">
export type asOut<t> = [t, asIo<t, "out">] extends [asIo<t, "out">, t]
? t
: asIo<t, "out">

type asIo<t, io extends "in" | "out"> = t extends ParsedMorph<infer i, infer o>
? io extends "in"
Expand Down

0 comments on commit 14d897d

Please sign in to comment.