Closed JGitHub01 closed 8 years ago
@JGitHub01 You are correct in that there are circumstances for which it would be great to have some supporting type guards at the ready.
The type guards, would, however, have to be implemented as actual typescript code, rather than definition files.
When I created a D3 service for Angular 2, I added a discussion issue for a roadmap, where I flagged the same idea as a future enhancement, see d3-ng2-service Issue 6.
In principle, this could also be a small stand-alone library, exporting relevant type guards. While, I would appreciate its existence, I have not gotten around to it yet due to other priorities (beyond D3/TS2) and with a need to first close out the remaining nice-to-have work items, I have already created on DefinitelyTyped to enhance the existing definitions. This specifically pertains to JSDoc comments and enabling strictNullChecks throughout.
That being said, I have not formalized a contribution process for d3-ng2-service, but are certainly open to collaboration on that repo, Conceivably, a separate helper module as well.
It's simply down to prioritization. There is a tracking issue on DefinitelyTyped issue 9936 for these D3 definitions. That thread might be a good place, if you want to raise the question of interest in type guards, but strictly speaking the solution would have to be outside DT as mentioned at the outset.
Cheers, T
There does not seem to be an easy way to distinguish for example between d3.ScaleLinear and d3.ScaleTime. I am wondering if it makes sense to add some kind of type property to make it easier.
There are other d3 types that may also need type guard. I wonder if it should be considered as a general practice.