Why is Route#data a type instead of an interface? #38111
Labels
area: router
cross-cutting: types
feature: under consideration
Feature request for which voting has completed and the request is now under consideration
feature: votes required
Feature request which is currently still in the voting phase
feature
Issue that requests a new feature
freq4: critical
P4
A relatively minor issue that is not relevant to core functions
state: confirmed
Milestone
🐞 bug report
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#data
property to add metadata for a specific route. Eg:permissions
information like the following:In my use-case, I'd like to type
Route#data
to have an optional propertyrequiredPermission
which is a Tuple of[PermissionNames, Privilege]
. And I want to enforce this type specifically forrequiredPermission
if it is added to aRoute#data
. Normally, I'd just go totypings.d.ts
(or whatever*.d.ts
you have at root) and override a library's interface there. Eg:But for the case of
Route#data
, it hastype Data = {}
tied to it andType
does not allow for Declaration Merging so TypeScript doesn't allow me to overrideRoute#data
as 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
![image](https://user-images.githubusercontent.com/25516557/87784074-406faa00-c7fb-11ea-9b23-870dbe8502f9.png)
![image](https://user-images.githubusercontent.com/25516557/87784084-436a9a80-c7fb-11ea-92bb-3c3a849c9172.png)
![image](https://user-images.githubusercontent.com/25516557/87784090-46658b00-c7fb-11ea-8181-00448b15b41b.png)
Route#data
was 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 withType
instead ofinterface
.Type
rather thanInterface
for these cases?Type
other thanRoute#data
to change those intoInterface
?🔬 Minimal Reproduction
A good way to reproduce this (as the screenshots above have shown) is to:
typings.d.ts
on the same level asmain.ts
(or use existing*.d.ts
on that same level)Data
to 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
-->
🌍 Your Environment
Angular Version:
The text was updated successfully, but these errors were encountered: