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

Rewrote SharedProps Type declaration so usePage is not throwing errors #50

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

Barabasbalazs
Copy link

πŸ”— Linked issue

#46

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

By rewriting the config template like this:

declare module '@adonisjs/inertia/types' {
  export type SharedProps = InferSharedProps<typeof inertiaConfig> & {}
}

and by removing this interface declaration from the types:

export interface SharedProps {}

The SharedProps type is easily extended by the user like this:

declare module '@adonisjs/inertia/types' {
  export type SharedProps = InferSharedProps<typeof inertiaConfig> & {
      prop1: number
      prop2: string
  }
}

and the usePage hook from @inertia/react is able to deduce the prop type declared here as well.

inertia_prop_type_extended

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Serialize<
InferProps<Extract<Awaited<ReturnType<Controller[Method]>>, PageObject>['props']> &
SharedProps
>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we need it here too. Otherwise SharedProps won't be available when using InferPageProps

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