D
D
danilr2019-11-20 07:00:34
typescript
danilr, 2019-11-20 07:00:34

How to type a function that returns a function with parameters?

export const getAnalytic = (action: Action) => {
    try {
        const operations = new Operations();
        const analyticsLog = {
            action,
            total: 1,
        };

        return (isSuccess: boolean, param: string = '') =>
            operations .track({
                ...analyticsLog,
                type: param,
                itemsSuccess: Number(isSuccess),
                itemsError: Number(!isSuccess),
            });
    } catch (error) {
        return error;
    }
};

Need to type getAnalytic (it returns a function with parameters)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2019-11-20
@danilr

And what exactly is not typed for you now?
the typescript should display all types here on its own.
If you need some kind of interface, depending on which one.
For example

typeof getAnalytic
ReturType<typeof getAnalytic>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question