Why is Route#data a type instead of an interface? #38111
Milestone
Comments
|
Related issue #27240 |
|
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Affected Package
The issue is caused by package @angular/routerDescription
A clear and concise description of the problem...When we work on the routing configuration, sometimes we leverage the
Route#dataproperty to add metadata for a specific route. Eg:permissionsinformation like the following:In my use-case, I'd like to type
Route#datato have an optional propertyrequiredPermissionwhich is a Tuple of[PermissionNames, Privilege]. And I want to enforce this type specifically forrequiredPermissionif it is added to aRoute#data. Normally, I'd just go totypings.d.ts(or whatever*.d.tsyou have at root) and override a library's interface there. Eg:But for the case of
Route#data, it hastype Data = {}tied to it andTypedoes not allow for Declaration Merging so TypeScript doesn't allow me to overrideRoute#dataas the above screenshot shows. This prevents me from enforcing the correct typings forrequiredPermission, hence leads to bad Developer Experience (in our cases) and Runtime bugs (instead of Compilation time).If



Route#datawas an interface (which allows for Declaration Merging), I could indeed achieve the following:Before writing up this issue, I was going to submit a PR right away to "fix" the bug. But looking at the source code, there are many different places (other than
Route#data) being given types withTypeinstead ofinterface.Typerather thanInterfacefor these cases?Typeother thanRoute#datato change those intoInterface?A good way to reproduce this (as the screenshots above have shown) is to:
typings.d.tson the same level asmain.ts(or use existing*.d.tson that same level)Datato have custom typed properties:Issues that don't have enough info and can't be reproduced will be closed.
You can read more about issue submission guidelines here: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-submitting-an-issue
-->
Angular Version:
The text was updated successfully, but these errors were encountered: