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

feat: handle tuple defaults #1148

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions ark/type/__tests__/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ark/type/keywords/inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ type _distill<t, opts extends distill.Options> =
: t extends of<infer base, infer attributes> ?
opts["branded"] extends true ? of<_distill<base, opts>, attributes>
: "brand" extends keyof attributes ? brand<_distill<base, opts>, attributes>
: attributes extends Default<base> ? base
: _distill<base, opts>
: unknown extends t ? unknown
: t extends TerminallyInferredObject | Primitive ? t
Expand Down
Loading