'Is it possible to create a conditional type based on a literal array type?

I'm wondering if it's possible to create a conditional type based on if a value is in an array of literal values:

export type UseTablePlugins = "search" | "pagination";

function useTable<Plugins extends UseTablePlugins[]>(plugins: Plugins) {
  ...
  
  // This is the part I'm stuck on
  return searchState: Plugins extend "search"[] ? [string, Dispatch] : never;
}

I know TypeScript goes away on runtime and therefore is unable to find the values of variables, but I'm wondering if I do something like useTable(["search"]) if TypeScript will understand that search is in the type? I hope I'm making sense :).

EDIT: Here is a minimal example on TS playground.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source