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
{{ message }}
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
Is it intentional that it doesn't work with anonymous types?
constassertPerson=assertTypeFn<{name: string;}>();// <-- does not workassertPerson(json).unwrap();
(2) I haven't found any way to pass the type via a generic parameter to some library function:
// json-request.tsexportasyncfunctionjsonRequest<TRes>(url: string){constjson=awaitfetch(url);// do some more magic there too, like loggingconstasserter=assertTypeFn<TRes>();returnasserter(json).unwrap();// <-- does not work}// some-file.tsimport{jsonRequest}from"json-request";
...
constres=awaitjsonRequest<{name: string;age?: number;}>("https://example.com");// I want res here to be (a) strongly typed and (b) validated at run-time
Probably it's expected, because TS transformer works locally and doesn't trace the callers. My question here is - how do I express something similar to this? Because the above syntax (some-file.ts) is basically the essence of what's needed in 99% of the cases... especially in the code which sends lots of different requests, and each request is mentioned there only once (so it makes no sense to create a named type for its response structure).
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi.
Two questions:
(1) In all examples, the type is first defined as a named interface (or a type) and only then its name is passed to assertTypeFn:
Is it intentional that it doesn't work with anonymous types?
(2) I haven't found any way to pass the type via a generic parameter to some library function:
Probably it's expected, because TS transformer works locally and doesn't trace the callers. My question here is - how do I express something similar to this? Because the above syntax (some-file.ts) is basically the essence of what's needed in 99% of the cases... especially in the code which sends lots of different requests, and each request is mentioned there only once (so it makes no sense to create a named type for its response structure).
The text was updated successfully, but these errors were encountered: