Skip to content

fix(svelte): remove optional markers from defineWidget component props#1004

Closed
abhi-0203 wants to merge 2 commits into
manzt:mainfrom
abhi-0203:fix/svelte-typing
Closed

fix(svelte): remove optional markers from defineWidget component props#1004
abhi-0203 wants to merge 2 commits into
manzt:mainfrom
abhi-0203:fix/svelte-typing

Conversation

@abhi-0203

Copy link
Copy Markdown

Summary

Removes the optional markers (?) from the model and bindings props in the JSDoc type annotation for defineWidget.

Problem

The defineWidget function in @anywidget/svelte expects a Svelte component typed as:

svelte.Component<{ model?: AnyModel<T>, bindings?: T }>

This makes model and bindings optional (can be undefined), but in reality they are always passed to the component in the render method. This causes TypeScript to require either explicit handling of undefined values or explicit type casts in user code.

Solution

Change the type to:

svelte.Component<{ model: AnyModel<T>, bindings: T }>

This correctly reflects that both props are always provided, eliminating the need for unnecessary undefined checks in user components.

Closes #1000

The `defineWidget` function always passes `model` and `bindings`
to the Svelte component, so the JSDoc type should not mark them as
optional (`?`). This was causing TypeScript to require explicit
handling of `undefined` values or explicit type casts in user code.

Closes #1000
@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 159a686

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

This PR includes changesets to release 1 package
Name Type
@anywidget/svelte 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

@abhi-0203 abhi-0203 closed this by deleting the head repository Jul 8, 2026
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.

Incorrect typing in @anywidget/svelte

1 participant