Skip to content

fix: AsArgs default value type#15681

Open
paoloricciuti wants to merge 1 commit intomainfrom
fix-types-of-as-args
Open

fix: AsArgs default value type#15681
paoloricciuti wants to merge 1 commit intomainfrom
fix-types-of-as-args

Conversation

@paoloricciuti
Copy link
Copy Markdown
Member

The current types are a bit weird to work with...since it's expecting something if you have a variable that can be null or undefined it will yell at you (even tho it doesn't make sense since undefined is technically an acceptable value).

Furthermore the (string | {}) trick doesn't make sense here where the value can be anything (a number for example).

There's still one issue that I wasn't fully able to solve yet: for checkbox if you have a boolean value TS will complain because boolean is not assignable to true and false which is what the type is expecting (actual strict values, not just boolean).

Do you have any ideas on how to fix this?

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: e3b6932

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link
Copy Markdown

@henrykrinkle01
Copy link
Copy Markdown
Contributor

I'm glad this is being worked on. It's been bugging me since release.
I hope you can fix the type for the discriminator in a discriminated union schema as well. For example:

const base = z.object({ /* some fields */})

const type1 = base.extend({
    typeId: z.literal(1),
    /* other fields */
})
const type2 = base.extend({
    typeId: z.literal(2),
    /* other fields */
})
const combined = z.discriminatedUnion('typeId',
    [type1, type2]
)

TS doesn't even accept literal values like 1 or 2:

Argument of type '1' is not assignable to parameter of type '"number" | "range"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants