const typeGuard_= <U extends T, T>(o: T): o is U => true;
const o: number =33;
assert(typeGuard_<33, typeof o>(o));
o; //<= o is 33
//It would be nice to be able to do:
assert(typeGuard_<33>(o));
//...and have the compiler infer the type of T.
//...and even nicer to be able to do
const trustMe= <U extends T, T>(o: T): asserts o is U => {};
trustMe<33>(o);
Created
March 25, 2020 18:34
-
-
Save garronej/2d5bd80c8c6d4cd45566426316a6c050 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment