FlowJS: Extract type from Union

Viewed 83

Is it possible in flowjs to extract type from Union type?

I tried the following example, but no luck.

type ExtractType = <T>(T | () => T) => T;
type Config = string | () => string;
type S = $Call<ExtractType, Config>;

const str1: S = 'str'; // Error: requires function
const str2: S = () => 'str'; // Error: requires string

try flow

1 Answers

I simplified the very first line a bit, and it seems to do the job:

type ExtractType = <T>(T) => T;
Related