SansPapyrus683S
tRPC2y ago
2 replies
SansPapyrus683

is there a better way to do this?

  let query;
  let params;
  switch (getWhat) {
    case "posts":
      query = api.user.userPosts;
      params = { user: uid, what: "posts", cursor: at };
      break;
    case "likes":
      query = api.user.userPosts;
      params = { user: uid, what: "likes", cursor: at };
      break;
    case "following":
      query = api.user.followedPosts;
  }

  //@ts-ignore
  const { data, isPlaceholderData } = query.useQuery(params, {
    //@ts-ignore
    placeholderData: (prevRes) => prevRes ?? initPosts,
  });
so i have a component that renders a post list according to varying api calls
however, this requires the two ts-ignore at the bottom.
is there a way to tell ts that the two api calls result in the exact same type?
Was this page helpful?