From 14d897db35df9a3a96d27eb1d14b8b08f4b3cb48 Mon Sep 17 00:00:00 2001 From: David Blass Date: Mon, 23 Oct 2023 11:39:23 -0400 Subject: [PATCH] fix: extracted morph inference --- dev/configs/.changeset/heavy-melons-approve.md | 5 +++++ dev/test/morph.test.ts | 4 ++++ src/scopes/type.ts | 8 ++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 dev/configs/.changeset/heavy-melons-approve.md diff --git a/dev/configs/.changeset/heavy-melons-approve.md b/dev/configs/.changeset/heavy-melons-approve.md new file mode 100644 index 0000000000..172ce67d92 --- /dev/null +++ b/dev/configs/.changeset/heavy-melons-approve.md @@ -0,0 +1,5 @@ +--- +"arktype": patch +--- + +Fix an issue causing some morphs to not be properly extracted when .infer(red) diff --git a/dev/test/morph.test.ts b/dev/test/morph.test.ts index bc49ac4947..94a842b8a1 100644 --- a/dev/test/morph.test.ts +++ b/dev/test/morph.test.ts @@ -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({ diff --git a/src/scopes/type.ts b/src/scopes/type.ts index 8cb22aeb79..356c513fc3 100644 --- a/src/scopes/type.ts +++ b/src/scopes/type.ts @@ -105,9 +105,13 @@ export type AnonymousTypeName = `λ${string}` export const isAnonymousName = (name: string): name is AnonymousTypeName => name[0] === "λ" -export type asIn = asIo extends t ? t : asIo +export type asIn = [t, asIo] extends [asIo, t] + ? t + : asIo -export type asOut = asIo extends t ? t : asIo +export type asOut = [t, asIo] extends [asIo, t] + ? t + : asIo type asIo = t extends ParsedMorph ? io extends "in"