You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In non-strict mode, everything is assignable to {} except for void.
In strictNullChecks, you get a problem because you have to write {} | null | undefined; it's annoying.
Can just write an alias!
That way you can still get narrowing; check != null and then you'll be able to call toString() on it.
Problem: If we put this in lib.d.ts, you can run with skipLibCheck and TypeScript won't always print that out because it won't have seen the alias.
We could fix this in strictNullChecks mode by forcing the checker to resolve this.
But then in non-strictNullChecks mode,
What about failed type argument inference?
Could default to unknown instead of {}?
But not clear you get a lot of value from that.
Could also not do anything.
Problem: implies you'd need to change the constraint; implementations of generic functions currently make the assumption that type parameters will not be null or undefined (constraint is implicitly {}).
More Special Declaration Types in JS
#21974
In 2.7, we started treating variables initialized with empty object literals as namespaces in JS files.
Now you can omit the
var
Also allows IIFEs to be namespaces.
[[Daniel: I'm going to stop here because you can just read the PR writeup.]]
var
declarations as opposed to justconst
s?var
..js
file to a.ts
file..ts
and you become temporarily untyped even if you want.ts
?allowJs
just permitted this?.ts
in existing JS code.The
unknown
type#10715
{}
except forvoid
.strictNullChecks
, you get a problem because you have to write{} | null | undefined
; it's annoying.!= null
and then you'll be able to calltoString()
on it.lib.d.ts
, you can run withskipLibCheck
and TypeScript won't always print that out because it won't have seen the alias.strictNullChecks
mode by forcing the checker to resolve this.strictNullChecks
mode,unknown
instead of{}
?null
orundefined
(constraint is implicitly{}
).x > 0
imply narrowing?if (x)
narrows to{}
?if (!x)
narrows to{} | null | undefined
?{ [s: string]: unknown }
mean?unknown | T
?{}
?s!
?{}
object | string | number | boolean
).Distribute
keyof
on intersections#22300
This now works as expected!
The text was updated successfully, but these errors were encountered: