-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Proposal: Expose Undefined type as an occupied bottom type #1298
Copy link
Copy link
Closed
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Metadata
Metadata
Assignees
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Type
Fields
Give feedbackNo fields configured for issues without a type.
Proposal
The TypeScript spec says that
Undefinedis the subtype of all types (see 3.2.6).The keyword
UndefinedorNothingshould be added to the language to refer to the type ofundefined.typeof(undefined)currently yieldsany. This should be corrected to return the undefined type.Detail
See http://en.wikipedia.org/wiki/Bottom_type & http://james-iry.blogspot.com/2009/08/getting-to-bottom-of-nothing-at-all.html
The neat thing about structural typing TypeScript is that you don't need to explicitly think about generic type variance. Instead, when you use two generic implementations of non-identical types, then TypeScript uses the input and return types of the different methods and properties to figure out if these two generic types are subtypes or not.
One missing feature, however, seems to be a bottom Nothing/None/Nil type that is a subtype of all types. This then allows us to create neat "empty" types in generic.