My function is defined as:
export function useSubmitHandler(url: string, data: Json): [FormEventHandler<HTMLFormElement>, boolean] {}
The definition of Json
is as follows:
type JsonPrimitive = string | number | boolean | null | undefined
interface JsonMap extends Record<string, JsonPrimitive | JsonArray | JsonMap> {}
interface JsonArray extends Array<JsonPrimitive | JsonArray | JsonMap> {}
export type Json = JsonPrimitive | JsonMap | JsonArray
An error occurs when trying to pass an arbitrary interface to the function:
TS2345: Argument of type 'Fee' is not assignable to parameter of type 'Json'.
Type 'Fee' is not assignable to type 'JsonMap'.
Index signature is missing in type 'Fee'
https://i.sstatic.net/yOUGC.png
However, if the object is spread like {...store.data}
then the error disappears.
What modifications are needed to the useSubmitHandler
type to accept any JSON stringifyable object?
The structure of Fee
is:
interface Fee {
id: number|null;
name: string;
type: string;
amount: string;
default: number;
company_id: number;
deleted_at?: any;
active: number;
fee_or_discount: string;
}
The goal is for this solution to be compatible with any type.