From 39ce5d9ce25f3a7ba9b1274e54238db04769f26c Mon Sep 17 00:00:00 2001 From: Tyler <26290074+thegitduck@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:14:48 -0700 Subject: [PATCH 1/2] feat: handle tuple defaults I know this does not currently work but hopefully it shows my current misunderstanding and I could get a point in the right direction For now, I'll just plan to revisit this tomorrow night and see how far I can get closes #951 --- ark/type/__tests__/defaults.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ark/type/__tests__/defaults.test.ts b/ark/type/__tests__/defaults.test.ts index 3787c5069..0f1bf30ca 100644 --- a/ark/type/__tests__/defaults.test.ts +++ b/ark/type/__tests__/defaults.test.ts @@ -71,6 +71,13 @@ contextualize(() => { ) }) + it("tuple with default", () => { + const o = type(["string", ["number", "=", 5]]) + + attest<[string, number?]>(o.inferIn) + attest<[string, number]>(o.infer) + }) + it("defined with wrong type", () => { attest(() => // @ts-expect-error From 647f23bb035a0cb9b1ab2f9e4f467d4cb1c79f34 Mon Sep 17 00:00:00 2001 From: Tyler <26290074+thegitduck@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:25:56 -0700 Subject: [PATCH 2/2] chore: second attempt - still doesnt work pretty stuck on this tbh --- ark/type/keywords/inference.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ark/type/keywords/inference.ts b/ark/type/keywords/inference.ts index 33bc0ed33..0c014930c 100644 --- a/ark/type/keywords/inference.ts +++ b/ark/type/keywords/inference.ts @@ -220,6 +220,7 @@ type _distill = : t extends of ? opts["branded"] extends true ? of<_distill, attributes> : "brand" extends keyof attributes ? brand<_distill, attributes> + : attributes extends Default ? base : _distill : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t