-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Design Meeting Notes, 3/22/2019 #30547
Comments
@ahejlsberg I believe #28445 fits into the category of issues you were looking into for the first part of the design meeting - minimally I can confirm that the code behaves as expected when the contextual type is instantiated with the nonfixing parameter mapper. |
Also maybe #29775 ? It looks similar (identical?), anyway. |
Not sure if this is the best place to comment. Apologize if not :) Super excited about the strictly-typed generator! Just curious, what does I'm actually thinking about the same thing (if I understand the sentence correctly), where generator can somehow simulate a state machine, where each time a |
@rbuckton can explain but the idea is that you can pass in values to calls to function* foo() {
let x: number = yield; // This 'yield' expression is contextually typed as 'number'
console.log("x is", x);
}
var iterA = foo();
iterA.next(0); // the first call to 'next()' is ignored, but the argument is type-checked
iterA.next(100); // this argument is also type-checked, and at runtime this logs 'x is 100'
var iterB = foo();
iterB.next("hello"); // error! 'string' is not assignable to 'number'
iterB.next(100); // error! 'string' is not assignable to 'number' |
@DanielRosenwasser is correct. Also keep in mind that we will aggregate all of the types used in this way: function* foo() { // : Generator<undefined, void, A & B>
let x: A = yield;
let y: B = yield;
} We would have to intersect the provided types as we cannot type a generator in such a way as to "unroll" the types used on each iteration. As a result, what you send into the generator must satisfy all of the possible input values. |
Thanks guys for responding! I wasn't thinking about the intersection thing, now I get it :) |
Avoiding fixing during inference
T
for a function expression for contextual typing often "fixes" a type parameter to its constraint{}
.3.4 Breaks
#30390
true | false
when we sayboolean
.#30419
Remove block-scoped bindings from
globalThis
#30477
#30510
let
andconst
andclass
shouldn't show up onthis
,global
,window
, orglobalThis
.master
.Object
,Number
,String
back fromconst
tovar
const
?var
?const var
?readonly var
?public static void readonly virtual var
?const
tovar
.keyof typeof globalThis
?Strictly-typed Generators
#2983
typesVersions
.{ foo: "red" | blue" }
➡{ foo: "red" } | { foo: "blue" }
strictGeneratorTypes
so this becomes opt-inyield
as well.Generator<YieldOutputType, OutputType, NextInputType>
yield
expressions use contextual types to infer their input type (i.e. what a caller can give when they have.next()
).strict
?The text was updated successfully, but these errors were encountered: