-
Notifications
You must be signed in to change notification settings - Fork 3k
Add test for type definition validation? #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It sounds cool... @robwormald @jeffbcross what do you think about this? Do you guys do anything similar for Angular? |
Yeah, I think this is a great idea. It's a little tricky to test, but the original issue that I posted cropped up by doing something similar: class Response {
constructor(private _text:string){}
toJson():Object { return JSON.stringify(this._text); }
}
let o = new Observable(obs => {
obs.next(new Response('{"foo":"bar"}'));
obs.complete();
});
obs.map(res => res.toJson()).subscribe() //complains - {} does not have a .toJson() method! should be just a matter of setting up TS to compile some basic usage code with some typed classes. Would be happy to contribute here if you can get the mechanics set up @kwonoj |
In angular2, our tests are written in TS and so such issues get caught when the tests are being compiled. |
As @robwormald mentioned, main difference between ng2 is RxJS test cases are written in JS. I'll try to spend some times to think about ergonomics setup for this and create PR for proposal. |
This could be achieved moving current test cases into typescript based one as same as Angular2 does, if circumstances allows. |
I'm assigning this myself for evaluating if current test cases can be moved into typescript based one. |
Currently there are 3 (including this) way proposed,
|
@kwonoj, I'll defer to you on this one. Personally, I kind of like the first option. But that might be to costly in terms of time/benefit. |
Will take this, in discussion with @david-driscoll who has one of proposal's listed. |
I had the compiler only tests because it allows me to quickly validate if the type definition is clear and correct. I think they have value because they let you just compile out edge cases (expanding arguments until we variadic types for example). |
@david-driscoll proposal's in here are mostly for those for now. (If you see other PR, those are also just validate compilation only as well). Might be expanded later, but not sure if it can be actually due to its nature. |
@david-driscoll , let's narrow down discussion from 3 proposal to 2 proposal. In core sense one of my proposal in #667 and yours #1189 is actually identical, by
The only difference is usage of compiler, while my PR uses compiler api (https://github.com/ReactiveX/RxJS/pull/667/files#diff-ab8a473f2a92e6517f9ada975e3ddb11R34) instead of let compile anything down, it gives small conveniences of not emitting compilation results per those test. So in my mind, I'd like to discuss in this way
(Let's think about ergonomics first to make actual changes happen) Would it be ok? or strong preferences to use compiler instead of using its api? |
Nope! I just used the compiler because it was easier. 😄 |
Cool :) Let me come up with some pros vs. cons between those two then, discuss & decide from that point to bring this changes are checked in. |
Now several type definition enhancements wanted to be ready before this are landed (or coming), think we can get back to this. As mentioned above, main thing to finalize is organization of test for type definition between using exist test case or having separate one. My personal take on those are convert existing test case to typescript based one, then add type definition test as set of existing specs. Pros
Cons
Though there are some cons, I think this is worth effort. I may possibly missing either pro or cons, so any opinion would be appreciated. I'll gather some opinion and try to proceed in one way. /cc @david-driscoll , @masaeedu , @saneyuki also. |
I'm cool with whatever, and will help out where ever I can to get things working correctly. |
@kwonoj Adding tests for the type signatures themselves seems a bit overkill to me, but I would definitely be for migrating the unit tests to use TypeScript. This way you'll be able to quickly spot pain points TypeScript users are facing when writing tests. |
The only reason I like having compiler based tests for the signatures, is it lets you see what happens in complex cases with overloads. In some cases, due to how TypeScript manages overload resolution order of your overload can mean the difference between the overload being found or not. Some operators this won't be necessary, as their tests would do the same thing. Other operators with more overloads, like zip, combineLatest, then it might make sense. |
Updating status to notify this issue is not dead. I'm currently have work in progress changes for initial PR to migrate test cases into typescript to support type validation test as well, expecting to present it soon. Once this PR can be landed in codebase, quite lot of further tasks can be progressed based on this. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
There are some cases of type definition does not work as expected like reported issue #660, #642, #635, Came to feel it'd be helpful if there's compile-time type signature validation test is included CI.
It'll not be kind of unit test, simply write down basic signatures of operator invocation in typescript instead of plain javascript, let CI try to compile it only (does not execute). Compilation result will tell if current type signature works in expected way or not. Course it can't cover whole aspect of signature, but at least can have minimum lines of basic usages.
The text was updated successfully, but these errors were encountered: