Skip to content

Suggested way to infer Params returned #109

@codytooker

Description

@codytooker

Is it possible to infer the types returned form inertia.render(). This would be a huge value proposition I think for inertia with adonis.

As a quick example say I have a controller like so

import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

export default class FooController {
  public async index({ inertia }: HttpContextContract) {
 
    return inertia.render('Foo', {
      title: "This is the title",
    })
  }
}

With React and Typescript I currently do something like this

interface FooPageProps {
   title: string
}

const FooPage = ({ title }: FooPageProps) => {
    return <div>{title}</div>
}

The problem here is that we aren't really getting good types because we are basically just telling the component what it has not what it will actually receive. It would be extremely valuable to do something like the following

const FooPage = ({ title }: InertiaResponse<FooController['show']>) => {
    return <div>{title}</div>
}

I am not a Typescript expert but I really wonder if this could be possible using some combination of ReturnType and infer

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestinvestigateNot sure about something

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions