Skip to content

Vue page props Data.* are inferred as any #87

@flozdra

Description

@flozdra

Package version

4.2.0

Describe the bug

When defining a page props with the generated types from '@generated/data in a Vue page with Data.*, the inferred props type in the ctx.inertia.render function is any.

// inertia/pages/auth/login.vue
import { Data } from '@generated/data'

defineProps<{ foo: Data.User }>()
// app/controllers/session_controllers.ts
import type { HttpContext } from '@adonisjs/core/http'

export default class SessionController {
  async create({ inertia }: HttpContext) {
    return inertia.render('auth/login', {
      foo: 'any', // The inferred type of "foo" is "any"
    })
  }
}

The issue is visible when defining a Data.* object at the root level (defineProps<{ foo: Data.User }>())
but when defining an array defineProps<{ foo: Data.User[] }>, the inferred type is shown as Data.User[] but Data.User is still any.

// inertia/pages/auth/login.vue
import { Data } from '@generated/data'

defineProps<{ arrayFoo: Data.User[] }>()
// app/controllers/session_controllers.ts
import type { HttpContext } from '@adonisjs/core/http'

export default class SessionController {
  async create({ inertia }: HttpContext) {
    return inertia.render('auth/login', {
      arrayFoo: ['any', 1],
      // The inferred type is correct (PagePropsEagerDataTypes<Data.User[]> | MergeableProp<UnPackedPageProps<Data.User[]>>)
      // but "Data.User" is still considered as "any" since the function accepts "['any', 1]"
    })
  }
}

Note: there is not such issue when using Inertia + React

Reproduction repo

https://github.com/flozdra/inertia-render-props-vue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions