userMod2
userMod2

Reputation: 9000

Typescript - Parameter in Function Expression

I have this code - where I'm trying to pass in a string title:

let GetData: (title: string) => Promise<APIStates<Series[]>>;

if (process.env["REACT_APP_SERVICE_VERSION"] === "development") {
    GetData = useGetDataServiceDummy(title)
}

However I keep getting 2 errors and can't figure out the syntax to resolve it:

Could someone please help me with the syntax to get around this error.

And for reference useGetDataServiceDummy

export async function useGetDataServiceDummy(title: string): Promise<APIStates<Series[]>> {
    // do soemthing with `title`
    return { status: "loaded", payload: dummyData };
}

Any help would be appreciated.

Thanks.

Upvotes: 1

Views: 43

Answers (2)

Serhan C.
Serhan C.

Reputation: 1298

If you want to assign useGetDataServiceDummy(title) function to GetData you should change your definition of GetData like this;

let GetData: Promise<APIStates<Series[]>>;

Upvotes: 0

lukasgeiter
lukasgeiter

Reputation: 153130

It looks like you're trying to assign useGetDataServiceDummy to GetData, however what you're actually doing is calling useGetDataServiceDummy and then assigning the return value to GetData. Try this instead:

if (process.env["REACT_APP_SERVICE_VERSION"] === "development") {
    GetData = useGetDataServiceDummy
}

Upvotes: 2

Related Questions