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
@ahejlsberg: It's hard to imagine a world where T? means onlyT | null or onlyT | undefined.
There is a school of thought that says "neither - this just doesn't need to exist".
Just ship two type aliases for T | null and T | undefined in lib.d.ts
We can sort of see that. It's not crazy.
We can't satisfy everyone - we're going to piss someone off.
But if we ship this without a ? type modifier, it's the first thing we're going to hear, and we're going to hear it for the rest of our lives.
What's crazy about T | null?
You have an optional accessor that returns number? | undefined.
You end up with these awkward, funny-looking types.
Lack of symmetry between optional members and nullish types.
Becomes like the const modifier in C++.
Nobody understands where the heck to put const (before *, after *, at the end of a signature), and the differences are hard for people to grasp.
We understand it, but our users will get tripped up a lot.
People will definitely be confused about which to do.
Users on GitHub did not seem to be concerned with it - they understood very well.
Confirmation bias - these are people who are interested in language design to begin with.
Too many people are doing null to ignore that scenario.
Ultimately the question becomes is this disjoint or does it combine with the "other" use of ? on optional parameters/properties.
@RyanCavanaugh: Extremely against T? meaning T | null | undefined because it muddies waters - So if we can't come to a conclusion, I think we should hold off on it.
We want to lead people to a pit of success, and we can't repeat the problem we have with modules.
Only consistency in discussion on thread is that there is no consistency.
We don't feel confident that we can do the "right" thing here out of the gate.
If people go out and fix type definitions and inappropriately use ?, then you've made the ecosystem worse - we need to wary of this possibility.
Answer to the question of "How do we easily resolve types for script/global code?"
Need to avoid situations where users have duplicate definitions due to "global code" being treated as conflicting even though they might refer to the same entities.
Syntax: /// <reference library="jquery" />
What is the order of resolution for declaration files?
Take /// <reference library="jquery" />.
Start from current module location.
Look for files walking up the spine of directories. For each directory:
If you see a file named jquery.d.ts, use that.
If you see a directory named typings, look in there.
If you see a directory named node_modules
Try to resolve in node_modules/jquery/package.json or use the node_modules/jquery/index.d.ts.
Try to resolve in node_modules/jquery/package.json or use the node_modules/@types/jquery/index.d.ts (or something similar).
Meeting cut short - may be more to the algorithm.
The text was updated successfully, but these errors were encountered:
Non-nullable types (#7140)
Question marks on types
Let's start the bike-shedding! What does
T?
mean?T?
means onlyT | null
or onlyT | undefined
.T | null
andT | undefined
inlib.d.ts
?
type modifier, it's the first thing we're going to hear, and we're going to hear it for the rest of our lives.T | null
?number? | undefined
.const
modifier in C++.const
(before*
, after*
, at the end of a signature), and the differences are hard for people to grasp.null
to ignore that scenario.?
on optional parameters/properties.T?
meaningT | null | undefined
because it muddies waters - So if we can't come to a conclusion, I think we should hold off on it.?
, then you've made the ecosystem worse - we need to wary of this possibility.lib.d.ts
.Optional members on new members
null
andundefined
#7426 (comment))let x?: number
).class Foo { x?: number }
).function val(x?: string)?: number
).[x: string]?: Entity
).undefined
by default, but non-nullable types make the world quite different.undefined
and reflects that in the type.?
in types?Control-flow based type checking
UMD module support (#7264)
export as namespace Foo
whereFoo
is some arbitrary identifier./// <reference path="..." />
, isFoo
visible.Foo
is always visible if the.d.ts
is in the compilation context.export =
.Sometimes modules have members that refer to themselves.
We're still flexible here!
Continue using some value, use
export =
, and then use anexport namespace as Foo
.Why does
/// <reference path="..." />
affect things? Why not just use a global module augmentation?Library include directives (#7263)
/// <reference library="jquery" />
/// <reference library="jquery" />
.jquery.d.ts
, use that.typings
, look in there.node_modules
node_modules/jquery/package.json
or use thenode_modules/jquery/index.d.ts
.node_modules/jquery/package.json
or use thenode_modules/@types/jquery/index.d.ts
(or something similar).The text was updated successfully, but these errors were encountered: