Closed
Description
Avoiding fixing during inference
- Requesting the type of a type parameter
T
for a function expression for contextual typing often "fixes" a type parameter to its constraint{}
. - Idea: when a function expression needs a contextual type, give the "current" view of the type to get the left side, but don't fix the type.
3.4 Breaks
- Not just "we do inference better so we catch more bugs"
- Maybe this is a larger problem - people really don't mean
true | false
when we sayboolean
.
- Maybe this is a larger problem - people really don't mean
- Have this implicit assumption that when you have an explicit return type annotation, when you return something that's assignable to that type, it should be "fine".
- Not true here.
- The literal types might be defensible. The problem is that we've discarded at least one branch of inference.
Remove block-scoped bindings from globalThis
- Turns out
let
andconst
andclass
shouldn't show up onthis
,global
,window
, orglobalThis
.- Uh oh. That's how it works in
master
. - We've never made a differentiation between
- Uh oh. That's how it works in
- Complications
- We'd also have to change things in the global scope like
Object
,Number
,String
back fromconst
tovar
- But you can change them! Why were they ever
const
?- Because you can "technically" do a lot of stuff in an untyped language, but that's not our bar.
- We'd also have to change things in the global scope like
- So how do you express a constant
var
?const var
?readonly var
?public static void readonly virtual var
?- Not 3.4-prioritized.
- We also down-level
const
tovar
.- Technically, at runtime you can access
- Sounds like we should do this today.
- Also, add a
keyof typeof globalThis
?
Strictly-typed Generators
- First we needed boolean literal types.
- Then we needed to not break Node so we needed
typesVersions
. - But we'd still hit a big breaking change by changing the type.
- Aside: this looks like an underlying issue where assigning an object type to a union fails, when assigning to the apparent type would otherwise have succeeded.
- e.g.
{ foo: "red" | blue" }
➡{ foo: "red" } | { foo: "blue" }
- Maybe we should look at fixing that first?
- Unions within/without types should be hoisted/canonicalized to improve type compatibility #14865
- e.g.
- Aside: this looks like an underlying issue where assigning an object type to a union fails, when assigning to the apparent type would otherwise have succeeded.
- Started looking into a
strictGeneratorTypes
so this becomes opt-in- Strongly typed return types, and strongly typed
yield
as well. - You can annotate the return type of a generator to be
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()
).
- Strongly typed return types, and strongly typed
- Can we do this without putting it under
strict
? - [[Out of time]]