Skip to content

[v2.x] fix: type error by changing page props type to any#2520

Merged
pascalbaljet merged 3 commits intoinertiajs:masterfrom
peaklabs-dev:fix-type-error
Aug 19, 2025
Merged

[v2.x] fix: type error by changing page props type to any#2520
pascalbaljet merged 3 commits intoinertiajs:masterfrom
peaklabs-dev:fix-type-error

Conversation

@peaklabs-dev
Copy link
Copy Markdown
Contributor

@peaklabs-dev peaklabs-dev commented Aug 17, 2025

Changes

  • fix: type errors. Example error: Type unknown is not assignable to type boolean. I get this error (and more for each line) when trying to use $page.props.username, because props are by default typed to unknown.

Example

Example 1:

    type FormValues = {
        username: string;
        notifications_enabled: boolean;
    };

    const defaultValues: FormValues = {
        username: $page.props.username,
        notifications_enabled: $page.props.notifications_enabled,
    };

Example 2:

  • Showing a flash message in svelte (I am aware I can get the flash message via $props() in svelte and type it there or leave it, which works because $props() has type of any). The following should be possible, but it is not currently, as I get type errors.
    {#if $page.props.flash.message}
      <div class="alert">{$page.props.flash.message}</div>
    {/if}

@pascalbaljet
Copy link
Copy Markdown
Member

I don't like to change this across all adapters, as in React/Vue you can do usePage<PageProps>(). Also, unknown in this case is preferred over any. Can't we make the change in packages/svelte/src/page.ts?

type SveltePage = Omit<Page, 'props'> & {
  props: Page['props'] & {
    [key: string]: any
  }
}

const { set, subscribe } = writable<SveltePage>()

@pascalbaljet pascalbaljet added svelte Related to the svelte adapter needs more info/work Needs more info from the author or additional work to get merged labels Aug 19, 2025
@peaklabs-dev
Copy link
Copy Markdown
Contributor Author

@pascalbaljet Thanks for the review. I have changed it, let me know if anything else is needed.

@pascalbaljet
Copy link
Copy Markdown
Member

Thanks! I've added a test so we know it keeps working in the future.

@pascalbaljet pascalbaljet merged commit 34190a2 into inertiajs:master Aug 19, 2025
5 checks passed
@peaklabs-dev peaklabs-dev deleted the fix-type-error branch August 19, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs more info/work Needs more info from the author or additional work to get merged svelte Related to the svelte adapter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants