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
My team maintains a moderately large Adonis application and we rely on type safety to catch bugs during refactoring. However, there is no kind of type checking for views β to check whether one passes the correct data to a view, one has to manually cross-compare the Edge file with the type in the controller. What's worse, one has to infer the type of the properties from their usage β and if they're passed into a subcomponent, one has to check the subcomponent. This adds overhead to our development process.
ποΈ High-Level Solution
1. Add an optional way to specify component's props (This feature request)
The amount of work one needs to do (in order to check that props in the view match the props in the controller) would significantly decrease if there was a standard way to denote all props a component takes. This props section could be entirely optional in order to keep backwards compatibility and to respect users that don't want type safety π
2. Add typechecking to view.render in Adonis (Future feature request)
Then, it wouldn't be too hard to add a command into Adonis, which would take all the prop types and generate a type definition for view.render (similar to astro sync or sveltekit sync). Then, TypeScript would make sure that developers can only pass properties of the same type that is declared in the Edge file.
3. Add typechecking to Edge's language server (Future feature request)
Last, and potentially the most difficult step, would be to integrate the type information into the language server / VS Code extension, so that the developer would get proper intellisense for props, and errors where they use them in an incorrect way.
π²οΈ Syntax / Bikeshedding
There are two important goals the syntax for describing props should have:
The types should be valid TypeScript. Rationale: Maintaining custom syntax for types would be a lot of work, and typechecking with TS would be harder.
It should be possible to compile Edge files without including a TypeScript parser. Rationale: TypeScript's type syntax is complicated (making the parser large/slow) and new versions often introduce new syntax (adding maintanance work to parser developers).
As long as these two goals are met, almost anything goes.
A nice syntax, that would be almost trivial for Edge to implement, is using Edge tags:
@props
name: string;
greeting?: string;
@end
The contents of the prop tag can be anything that is permitted inside interface Props { ... }.
The text was updated successfully, but these errors were encountered:
This seems like a great proposal and I think should be fairly simple to implement as well. However, the type-safety will only be for the TypeScript codebase all the internal usage of props within Edge templates will be untyped. This is because, Edge doesn't have a language server to impose type-safety
π§ The Problem
My team maintains a moderately large Adonis application and we rely on type safety to catch bugs during refactoring. However, there is no kind of type checking for views β to check whether one passes the correct data to a view, one has to manually cross-compare the Edge file with the type in the controller. What's worse, one has to infer the type of the properties from their usage β and if they're passed into a subcomponent, one has to check the subcomponent. This adds overhead to our development process.
ποΈ High-Level Solution
1. Add an optional way to specify component's props (This feature request)
The amount of work one needs to do (in order to check that props in the view match the props in the controller) would significantly decrease if there was a standard way to denote all props a component takes. This props section could be entirely optional in order to keep backwards compatibility and to respect users that don't want type safety π
2. Add typechecking to
view.render
in Adonis (Future feature request)Then, it wouldn't be too hard to add a command into Adonis, which would take all the prop types and generate a type definition for
view.render
(similar toastro sync
orsveltekit sync
). Then, TypeScript would make sure that developers can only pass properties of the same type that is declared in the Edge file.3. Add typechecking to Edge's language server (Future feature request)
Last, and potentially the most difficult step, would be to integrate the type information into the language server / VS Code extension, so that the developer would get proper intellisense for props, and errors where they use them in an incorrect way.
π²οΈ Syntax / Bikeshedding
There are two important goals the syntax for describing props should have:
As long as these two goals are met, almost anything goes.
A nice syntax, that would be almost trivial for Edge to implement, is using Edge tags:
The contents of the prop tag can be anything that is permitted inside
interface Props { ... }
.The text was updated successfully, but these errors were encountered: