-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[Bug]stricter Generators: T
not in scope
#32507
Comments
other examplecodefunction* foo(): {
next<T>(x: T): IteratorResult<T, void>;
} {
// x: T
const x = yield 1;
} Expected behavior
Actual behavior
|
T
not in scopeT
not in scope
T
not in scopeT
not in scope
This is #30790 (comment) and #32523. |
Your second example looks like it should be an error. If your generator return type says the definition for |
As odd as it looks, I'm not even certain that the first example is really an error. We contextually type the result of function * foo(): {
next<T extends string>(value: T): IteratorResult<unknown, void>;
} {
// x is 'T extends string'
const x = yield;
x.charAt(0); // ok
} @DanielRosenwasser, @RyanCavanaugh this seems like something that might warrant further discussion? |
Anyway parametric iterator methods are useless without supporting Rank-2 types. function* foo(): {
next<T>(x: T): IteratorResult<T, void>;
} {
// T is `undefined | number`.
yield undefined; // Return type is `undefined | number`, not `undefined`.
yield 1; // Return type is `undefined | number`, not `number`.
} https://prime.haskell.org/wiki/Rank2Types Overloading may help us but it also brings some inconveniences. function* foo(): {
next<T extends undefined>(x: T): IteratorResult<T, void>;
next<T extends number>(x: T): IteratorResult<T, void>;
} {
yield undefined; // Return type is `undefined`.
yield 1; // Return type is `number`.
} |
TypeScript Version: 3.6.0-dev.20190720
Search Terms:
Generators
Code
Expected behavior:
It is necessary to discuss how it should work
Actual behavior:
x: T
Related Issues:
#30790 #31639
The text was updated successfully, but these errors were encountered: