You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@woutervh- Are you okay if I submit a PR to add the following feature to the value returned by createAssertType() - see example below:
exportinterfaceMyType{prop: string;}exportconstMyType$=createAssertType<MyType>();
... // below are the illustrations:constasserted=MyType$(req.params);// throws if no matchconstmaybeAsserted=MyType$.to(req.params);// doesn't throw; returns MyType | undefinedconstprop=MyType$.is(req.params) ? req.params.prop : "no";// assertion guard
Motivation: I want to have a single entry point to the assertions on some type MyType with some opinionated name (like MyType$), and then, having this entry point, be able to access it in 3 different modes (throwing, optional, guard).
Another motivation for me is to move all the typescript-is related code to a separate monorepo module, then export all those $-assseters to be usable by other modules, and then keep only that independent module built with tsc+plugins (and have the rest of modules built by swc which doesn't support TS plugins).
P.S.
These is actually an even cooler syntax! No need for $, the type name and the const name can be identical:
Hi.
@woutervh- Are you okay if I submit a PR to add the following feature to the value returned by createAssertType() - see example below:
Motivation: I want to have a single entry point to the assertions on some type MyType with some opinionated name (like MyType$), and then, having this entry point, be able to access it in 3 different modes (throwing, optional, guard).
Another motivation for me is to move all the typescript-is related code to a separate monorepo module, then export all those $-assseters to be usable by other modules, and then keep only that independent module built with tsc+plugins (and have the rest of modules built by swc which doesn't support TS plugins).
P.S.
These is actually an even cooler syntax! No need for $, the type name and the const name can be identical:
The text was updated successfully, but these errors were encountered: