Last active
November 14, 2018 22:58
-
-
Save donabrams/9b16e548440938858025ced5b52831dd to your computer and use it in GitHub Desktop.
ArgsType.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ArgsType<T> = T extends (...args: infer R) => any ? R : never; | |
type Func1 = (a: string, b: boolean) => boolean; | |
type Func2 = () => void; | |
const pass1: ArgsType<Func1> = ["yay", true]; | |
const fail1: ArgsType<Func1> = ["yay"]; | |
const fail2: ArgsType<Func1> = [true, true]; | |
const fail3: ArgsType<Func1> = []; | |
const fail4: ArgsType<Func1> = ["yay", true, "boo"]; | |
const pass2: ArgsType<Func2> = []; | |
const fail5: ArgsType<Func2> = "boo"; | |
const fail6: ArgsType<Func2> = ""; | |
const fail7: ArgsType<Func2> = [null]; | |
const fail8: ArgsType<Func2> = null; // false pass, but ignorable | |
type Func3<R> = (f: (...T) => any) => ((...T) => R); | |
const f1 = (a: string, b: boolean):string => { return ''; }; | |
const f2 = (): any[] => ["yay"]; | |
const fluent = ((f) => (...args) => { | |
f(...args); | |
return {fluent: true}; | |
}) as Func3<{fluent: true}>; // I have no idea how to construct this | |
const pass3: {fluent: true} = fluent(f1)("yay", true); | |
const fail9: {fluent: true} = fluent(f1)("yay"); // TODO: FALSE PASS | |
const fail10: {fluent: true} = fluent(f1)("yay", "boo"); // TODO: FALSE PASS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment