Open simark opened 6 years ago
We could try to add a custom tslint rule for it.
Is there an advantage of doing a tslint plugin vs a compiler plugin?
ts compiler plugin is fine as well
I wonder if the problem really is big enough to pull the weight of such extra tools.
Well, I think it's really easy to make typos, update one and forget to update the other, forget to add a field to the "required" list, etc... And if there's an error, the consequence will be at runtime, so you may not see it in your testing.
When adding preferences, the pattern is to define a schema, such as
and then write a class that will be passed to
PreferenceProxy
.It is important to keep these two in sync, otherwise the
PreferenceProxy
will try to access undefined properties, or properties with the wrong type. It would be nice if we had a way to keep them in sync.The ideal way, I think, would be if we could generate the JSON schema based on the class in a Typescript compiler plugin. However, Typescript compiler plugins can't change how the javascript is emitted, so I don't think we can inject new code.
An alternative would be to write a plugin that checks that the class and the schema are equivalent, and produces a warning or an error if they are not.