I've these 3 fields in my form (sku, sku_variation, name) and I want to use them to create a new product.
I came up with this solution recasting the parsedData
to unknown first but it looks completely wrong.
export type TProduct = { id: string, sku: number, skuVariation: number, name: string, } export type TCreateProduct = Omit<TProduct, 'id'>; const createProduct = async(parsedData:TCreateProduct) => { fetch('http://localhost:3333/api/products/',{ method: 'POST', body: JSON.stringify(parsedData) }) return ''; } const handleSubmit = (e:React.FormEvent<HTMLFormElement>) => { e.preventDefault(); const form = new FormData(e.target as HTMLFormElement); const parsedData = Object.fromEntries(form.entries()) as unknown as TCreateProduct; createProduct(parsedData); }