Search code examples
javascriptreactjstypescriptnext.jsreact-tsx

define object type with dynamic number of key and value and also that values can have string or number value


i have a project with nextjs and typescript.i have a function with name of submit func. this function accept three argument.type with string type base end point with string type and my problem is whit third argument and i can't handle type for this argument.i want this argument accepted a object with dynamic number of keys and values and also that values can have string or number value. this is my submit func

 interface values {
    [key: string]: object;
}
 const submitFunc = (type: string, baseEndPoint: string, values: values) => {
 //some code
 }

for more explanation i want for example call my function as follow

submitFunc('login', '/auth/mobile', {
            'mobile': 0912855838,
            'password': 'serer434312'
        });

or

submitFunc('name', '/auth/name', {
            'name':'Max'
        });

and Etc

I would be very grateful if anyone could help me


Solution

  • interface values {
        [key: string]: string | number;
    }
    

    This will define an object with key as string and values as either string or number type