Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SharedProps returning error when used in usePage hook #46

Open
josevelaz opened this issue Nov 19, 2024 · 8 comments
Open

SharedProps returning error when used in usePage hook #46

josevelaz opened this issue Nov 19, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@josevelaz
Copy link

josevelaz commented Nov 19, 2024

Package version

1.2.2

Describe the bug

When augmenting the SharedProps interface like shown in the documentation, an error is raised by the usePage<SharedProps>() hook.

 tsserver: Type 'SharedProps' does not satisfy the constraint 'PageProps'.
   Index signature for type 'string' is missing in type 'SharedProps'. [2344]

Passing any value into the module augmentation causes it to break

declare module '@adonisjs/inertia/types' {
  export interface SharedProps extends InferSharedProps<typeof inertiaConfig> {
    props2: string
  }
}

If prop2: string is removed then the error above goes away

image

CleanShot 2024-11-19 at 10 52 14@2x

Reproduction repo

No response

@josevelaz
Copy link
Author

@Julien-R44 reaching out making sure you were able to replicate it?
I was able to replicate it off a new adonisjs project so it seems like its some broken functionality. Happening on v2 aswell, although im aware not much changed from v1 -> v2

@Julien-R44
Copy link
Member

Yup, can confirm this is a bug. I haven't had time to look into it yet. Happy to accept a PR

@Julien-R44 Julien-R44 added the bug Something isn't working label Dec 17, 2024
@Barabasbalazs
Copy link
Contributor

Barabasbalazs commented Dec 20, 2024

I think that by rewriting the template like this in the config/inerta.ts file,

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

and also removing this interface declaration from the types file can solve this issue:

export interface SharedProps {}

See:

inertia_shared_prop_types

@Julien-R44
Copy link
Member

Fixed by #50

@Julien-R44
Copy link
Member

Finally #50 wasn't enough, see #53

I reverted it until we found another solution. So, re-opening this issue

@Julien-R44 Julien-R44 reopened this Jan 5, 2025
@Barabasbalazs
Copy link
Contributor

@Julien-R44 I checked the implementation that I did and it seems to work for InferPageProps as well. Can you maybe provide some detail about how this PR broke that?

inferpageprops2

@Julien-R44
Copy link
Member

You need to configure InferPageProps correctly : point to a real controller that returns real data. For example, you could create this controller:

export class AboutController {
  async index({ inertia }: HttpContext) {
    return inertia.render('about', { bar: 42 })
  }
}

If you do this then you will be unable to access props.bar.
See https://docs.adonisjs.com/guides/views-and-templates/inertia#types-sharing

@Barabasbalazs
Copy link
Contributor

@Julien-R44 That's what I did.

about_controller

The type checking seems to be working but it looks like the props don't get passed properly to it from the controller. I don't think that this was the PR that broke it.
You can check out this repo in order to reproduce the issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants