Not sure this information is relevant, but here it is:
babel-plugin-macros version: 2.8.0
node version: 13.9.0
npm (or yarn) version: 6.14.4
I am trying to create a macro that takes in type information and uses it to generate compile time checking of objects. An example:
interface Asteroid {
type: 'asteroid'
location: [number, number, number]
mass: number
}
// the right hand side will be a function that accepts a object and validates that it is an asteroid
const validateAsteroid = createValidator(Asteroid)
Will the macro be aware that Asteroid is a typescript interface, or, will this information have already been stripped by the time the macro is executed?
I also realized that createValidator(Asteroid) is invalid Typescript syntax because the Typescript compiler complains that Asteroid is being used as a value. Are there any ways to call a macro with a Typescript type that avoid making IDEs complain? If not, I'd be willing to work on support for something like createValidator<Asteroid>() (or some alternative syntax), so that macros can accept Typescript types.
Update: After playing around here, I think I came to the conclusion that the Typescript type information is stripped after the macro is run, but, Asteroid is marked as an identifier in the abstract syntax tree, so, the macro cannot get any useful information out of it, which is unfortunate.
Not sure this information is relevant, but here it is:
babel-plugin-macros
version: 2.8.0node
version: 13.9.0npm
(oryarn
) version: 6.14.4I am trying to create a macro that takes in type information and uses it to generate compile time checking of objects. An example:
Will the macro be aware that
Asteroid
is a typescript interface, or, will this information have already been stripped by the time the macro is executed?I also realized that
createValidator(Asteroid)
is invalid Typescript syntax because the Typescript compiler complains thatAsteroid
is being used as a value. Are there any ways to call a macro with a Typescript type that avoid making IDEs complain? If not, I'd be willing to work on support for something likecreateValidator<Asteroid>()
(or some alternative syntax), so that macros can accept Typescript types.Update: After playing around here, I think I came to the conclusion that the Typescript type information is stripped after the macro is run, but,
Asteroid
is marked as an identifier in the abstract syntax tree, so, the macro cannot get any useful information out of it, which is unfortunate.