9
Is it possible to create a conditional type based on a literal array type?
Post Body
I'm wondering if it's possible to create a conditional type based on if a value is in an array of literal values:
```js 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's a minimal example for anyone who wants it :)
Author
Account Strength
90%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,041
Link Karma
556
Comment Karma
485
Profile updated: 3 days ago
Posts updated: 4 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/typescript/...