Skip to content
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

Suggestion: Export some internal type checking helpers #19602

Closed
raveclassic opened this issue Oct 31, 2017 · 4 comments
Closed

Suggestion: Export some internal type checking helpers #19602

raveclassic opened this issue Oct 31, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@raveclassic
Copy link

raveclassic commented Oct 31, 2017

I'm trying to implement a tslint custom rule to manually force and check yield typings inside of generator-based sagas from redux-saga. As the statuses of #2983 and similar issues are unknown it seems like custom rule is the only way for now.

So, at the moment I'm able to only force setting explicit type on the left side of yield expression:

const timePeriod = yield select(FilterSelectors.timePeriod);
          ^^^ error from custom rule - value has implicit any type                      

The next step is to extract the types of the left and right sides of such yield and it's possible with public TypeChecker#getTypeFromTypeNode.
Now when both types are available they could be checked for assignability with helpers under // TYPE CHECKING section in compiler/checker.ts in createTypechecker factory function (like checkTypeAssignableTo), but unfortunately they are isolated inside that factory.

Therefore I suggest exporting that helpers from compiler/checker.ts on the module-level (or under a namespace, or even as TypeChecker static fields), they will be very helpful for implementing such custom rules.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 31, 2017

Duplicate of #9879

@mhegazy mhegazy marked this as a duplicate of #9879 Oct 31, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 31, 2017
@raveclassic
Copy link
Author

@mhegazy Thanks for the pointing! Closing

@cloudify
Copy link

cloudify commented May 28, 2018

@raveclassic and anybody else looking at type checking saga yield calls: I've create a very crude custom tslint rule here.

The rules checks that the return type of the function passed to select and call matches the type of the variable on the left side of the yield and the types are matched using the result of typeToString.

It's not perfect, but it works for my needs, hope it helps.

@raveclassic
Copy link
Author

@cloudify Thanks! However we've dropped both redux and redux-saga and switched to rxjs completely.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants