Skip to content

Commit

Permalink
refactor: provide type in useSendPlatformRequest to infer in usages
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsinkamil committed Nov 22, 2023
1 parent a00c7e4 commit ecad163
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState } from 'react';

import q, { runQuery } from 'loot-core/src/client/query-helpers';
import { send } from 'loot-core/src/platform/client/fetch';
import { type SchedulesHandlers } from 'loot-core/src/server/schedules/types/handlers';
import { getRecurringDescription } from 'loot-core/src/shared/schedules';
import type {
DiscoverScheduleEntity,
Expand Down Expand Up @@ -130,10 +129,7 @@ export default function DiscoverSchedules({
modalProps: CommonModalProps;
actions: BoundActions;
}) {
const { data, isLoading } = useSendPlatformRequest('schedule/discover') as {
data: Awaited<ReturnType<SchedulesHandlers['schedule/discover']>> | null;
isLoading: boolean;
};
const { data, isLoading } = useSendPlatformRequest('schedule/discover');

const schedules = data || [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function useSendPlatformRequest<K extends keyof Handlers>(
args?: Parameters<Handlers[K]>[0],
options?: { catchErrors?: boolean },
) {
const [data, setData] = useState<unknown>(null);
const [data, setData] = useState<Awaited<ReturnType<Handlers[K]>>>(null);
const [isLoading, setIsLoading] = useState<boolean | null>(null);

useEffect(() => {
Expand Down
7 changes: 3 additions & 4 deletions packages/loot-core/src/server/schedules/find-schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,10 @@ export async function findSchedules() {
},
);

const finalized = [];
const finalized: Awaited<ReturnType<SchedulesHandlers['schedule/discover']>> =
[];
for (let schedule of schedules) {
finalized.push(await findStartDate(schedule));
}
return finalized as unknown as Awaited<
ReturnType<SchedulesHandlers['schedule/discover']>
>;
return finalized;
}

0 comments on commit ecad163

Please sign in to comment.