Reputation: 9000
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:
Cannot find name 'title'
Promise<APIStates<Series[]> is not assignable to (title: string) => Promise<APIStates<Series[]>
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
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
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