Skip to content

Instantly share code, notes, and snippets.

@dannyrb
Created December 12, 2024 15:36
Show Gist options
  • Save dannyrb/ce21e4b93d03ae12e7663cc4bfd51cc1 to your computer and use it in GitHub Desktop.
Save dannyrb/ce21e4b93d03ae12e7663cc4bfd51cc1 to your computer and use it in GitHub Desktop.

Revisions

  1. dannyrb created this gist Dec 12, 2024.
    18 changes: 18 additions & 0 deletions 01-get-function-return-type.solution.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    export type Expect<T extends true> = T;

    export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
    T,
    >() => T extends Y ? 1 : 2
    ? true
    : false;

    const myFunc = () => {
    return "hello";
    };

    /**
    * How do we extract MyFuncReturn from myFunc?
    */
    type MyFuncReturn = ReturnType<typeof myFunc>;

    type tests = [Expect<Equal<MyFuncReturn, string>>];