Please enable JavaScript.
Coggle requires JavaScript to display documents.
Top and bottom types - Coggle Diagram
Top and bottom types
Top types
⊤ is a type that describes any possible value allowed by the system.
{x| x could be anything }
any and unknown.
any
You can think of values with an any type as “playing by the usual JavaScript rules”
unknown
unknown can accept any value:
unknown is different from any in a very important way
Values with an unknown type cannot be used without first applying a type guard
Practical use of top types
ever convert a project from JavaScript to TypeScript
unknown is great for values received at runtime
obligating consumers of these values to perform some light validation before using them, errors are caught earlier, and can often be surfaced with more context.
Bottom type
never
const neverValue: never = myVehicle
// The exhaustive conditional
if (myVehicle instanceof Truck)
handling this a little more gracefully via an error subclass
class UnreachableError extends Error
no possible value allowed by the system.
any value from the following set: { }
Types describe sets of allowed values
const x: boolean
allowed values: {true, false}