A
arktype2mo ago
PIat

must be an instance of FormData (was object)

Hello! This code:
const formData = await request.clone().formData();

const formSchema = type({
name: 'string>0',
surname: 'string>0'
})

const parseForm = type('parse.formData').pipe(formSchema)

const formResult = parseForm(formData)
const formData = await request.clone().formData();

const formSchema = type({
name: 'string>0',
surname: 'string>0'
})

const parseForm = type('parse.formData').pipe(formSchema)

const formResult = parseForm(formData)
Throws following error:
must be an instance of FormData (was object)
must be an instance of FormData (was object)
However, formData is instanceof FormData and the log also says it's FormData:
ArkError {
input: {
code: 'proto',
description: 'an instance of FormData',
proto: [class FormData]
},
' arkKind': 'error',
path: [],
data: FormData { name: 'Plat', surname: '' },
...
ArkError {
input: {
code: 'proto',
description: 'an instance of FormData',
proto: [class FormData]
},
' arkKind': 'error',
path: [],
data: FormData { name: 'Plat', surname: '' },
...
What am I doing wrong?
27 Replies
ssalbdivad
ssalbdivad2mo ago
What did you see that makes you sure it's an instance of FormData? Try just creating it from new FormData() instead and see if that works
PIat
PIat2mo ago
I did console.log(formData)
ssalbdivad
ssalbdivad2mo ago
Did you try it with:
const formData = new FormData()
const formData = new FormData()
I need something I can actually repro
PIat
PIat2mo ago
This throws the same error
const formSchema = type({
name: 'string>0',
surname: 'string>0'
})

const parseForm = type('parse.formData').pipe(formSchema)

const data = new FormData()

data.append('name', 'Plat')
data.append('surname', '')

const formResult = parseForm(data)
const formSchema = type({
name: 'string>0',
surname: 'string>0'
})

const parseForm = type('parse.formData').pipe(formSchema)

const data = new FormData()

data.append('name', 'Plat')
data.append('surname', '')

const formResult = parseForm(data)
ssalbdivad
ssalbdivad2mo ago
Works for me
No description
PIat
PIat2mo ago
Aw :( Well, parse.number works inside of this package, but now it's formData
ssalbdivad
ssalbdivad2mo ago
I mean it would be one thing if it was unresolvable like before but you're saying this time that it's not an instanceof FormData but that's not the error I get
PIat
PIat2mo ago
No description
No description
ssalbdivad
ssalbdivad2mo ago
Can you just show me the error message .toString() like I did?
PIat
PIat2mo ago
No description
ssalbdivad
ssalbdivad2mo ago
You get that even if you just pass new FormData() directly to the validator?
PIat
PIat2mo ago
Yes, as per the first picture I'm on Node 20.14.0 Typescript 5.5.3 Arktype 2.0.0-beta.5
ssalbdivad
ssalbdivad2mo ago
May as well try beta.6 I can't repro it with those exact versions
PIat
PIat2mo ago
I tried the latest version, also installed it at the root of the workspace, so that there would only be one installation of Arktype, still the same error
ssalbdivad
ssalbdivad2mo ago
I tried my best to repro it you will have to link me a repo/branch I can clone
Want results from more Discord servers?
Add your server