Re:TypeScript please give us types
by scotty79 on Friday July 07, 2023 @05:41PM
(#36638691)
What if this macro could be expanded into valid typescript by preprocessor that runs before typescript compiler?
[ Parent
| on HN ]
Re:TypeScript please give us types
by armchairhacker on Friday July 07, 2023 @09:13PM
(#36640359)
That's an option, and maybe even the ideal one: an extension which takes a TypeScript+macros file and converts it into TypeScript before feeding to the TypeScript compiler.
However, such a preprocessor will basically need to re-implement TypeScript's type checking. So either TypeScript must expose it via an API, or the preprocessor needs to itself implement a subset (which as mentioned, could also be faster)
Re:TypeScript please give us types
by matt_kantor on Friday July 07, 2023 @10:14PM
(#36640706)
This already exists. One example posted elsewhere in these comments is tst-reflect[1], with which you can write this:
const fooType = getType<Foo>();
Which is exactly what you wanted, just as a plugin to TypeScript rather than built into the official compiler.