Skip to content
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
15 changes: 15 additions & 0 deletions ark/repo/scratch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ const darkColorLiteral = type.enumerated(
)

const darkColorRegex = type(`/^(${join(options, "|")})Dark$/`)

const literalValues = <t>(t: type.Any<t>): t[] => {
const literals: unknown[] = []
for (const branch of t.internal.branches) {
if (branch.hasKind("unit")) {
literals.push(branch.unit)
}
}
return literals as never
}

const palette = type.enumerated("red", "blue")

// ["blue", "red"]
literalValues(palette)
16 changes: 16 additions & 0 deletions ark/type/__tests__/fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,22 @@ contextualize(() => {
})
})

// https://github.com/arktypeio/arktype/issues/1614
it("labels an implementation that annotates its optional parameter", () => {
// labels come from the implementation's parameter names, which are only
// cosmetic. contextually inferred parameters already labelled correctly;
// it is annotating the optional one that stopped applyElementLabels from
// matching, dropping every label rather than just that one:
// (args_0?: number | undefined) => number | undefined
const f = type.fn("number?")((n?: number) => n)

attest(f).type.toString.snap(`TypedFn<
(n?: number | undefined) => number | undefined,
{},
{}
>`)
})

describe("scoped", () => {
it("scoped param and return", () => {
const $ = type.scope({
Expand Down
2 changes: 1 addition & 1 deletion ark/type/fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type BaseFnParser<$ = {}> = <
externalSignature extends Fn = (
...args: applyElementLabels<
distill.In<paramsT>,
Parameters<internalSignature>
Required<Parameters<internalSignature>>
>
) => args extends readonly [...unknown[], ":", unknown] ? distill.Out<returnT>
: ReturnType<internalSignature>
Expand Down
Loading