Skip to main content

type Foo

type Foo = () => () => string;

function func(foo: Foo): string {
    return foo()();
}
   
type Foo = () => string | () => () => string;

function func(foo: Foo): string {
    const f = foo();
    if (typeof f === 'function') {
      return f(); // Cannot return `f()` because function type [1] is incompatible with string [2].
    }
    return f;
}
   
type TF = () => string;
type Foo = TF | () => TF;

function func(foo: Foo): string {
    const f = foo();
    if (typeof f === 'function') {
      return f();
    }
    return f;
}