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

[bug] TypeScript definitions do not allow nested data on visits. #945

Closed
hailwood opened this issue Oct 19, 2021 · 2 comments · Fixed by #1401
Closed

[bug] TypeScript definitions do not allow nested data on visits. #945

hailwood opened this issue Oct 19, 2021 · 2 comments · Fixed by #1401
Labels
bug Something isn't working

Comments

@hailwood
Copy link
Contributor

hailwood commented Oct 19, 2021

Take the following request

Inertia.get('/somewhere', {
  name: 'bob',
  prefs: {
    color: 'red',
    food: 'apple'
  }
})

This does work and will do a visit to /somewhere?name=bob&prefs[color]=red&prefs[food]=apple

Unfortunately the TypeScript definitions do not allow the nested object so we're forced to @ts-ignore it or deal with

TS2322: Type '{ color: string; food: string; }' is not assignable to type 'FormDataConvertible'.   Type '{ color: string; food: string; }' is missing the following properties from type 'Date': toDateString, toTimeString, toLocaleDateString, toLocaleTimeString, and 37 more.

@jjorissen52
Copy link

I will also point out that using a FormData object (which does appease the type hints) does not add the get parameters to the URL.

@claudiodekker claudiodekker added bug Something isn't working todo labels Dec 3, 2021
@claudiodekker claudiodekker moved this to Not Started 🕑 in Inertia.js Dec 3, 2021
@claudiodekker claudiodekker removed the todo label Jan 4, 2022
@Tofandel
Copy link
Contributor

Tofandel commented Mar 18, 2022

Type issue is still there

Also arrays of objects are not serialized properly when used in a GET request without formData but objects are

eg:

Inertia.get('/somewhere', {
  arr: [{test: 1, test2: 2}]
})

Results in /somewhere?arr[][test]=1&arr[][test2]=2 which in PHP will result in [ 'arr' => [ ['test' => 1], ['test2' => 2] ] ] instead of [ 'arr' => [ ['test' => 1, 'test2' => 2] ] ]

and as @jjorissen52 pointed out if I force formData in a get request the parameters are not added to the URL

The only workaround is to use objects but this makes it a nasty workaround as arr: {0:{test: 1, test2: 2}} is serialized properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Closed 🚪
Development

Successfully merging a pull request may close this issue.

4 participants