3 ms·
> unknown is the set of all JS values. any is a paradoxical set that includes everything, but might also be empty. Not really a paradox. - `unknown` is the in
by clord 4y ago
> unknown is the set of all JS values. any is a paradoxical set that includes everything, but might also be empty.
Not really a paradox.
- `unknown` is the intersection (&) of all types, including an internal one that has no shape or characteristics. `unknown | {int: number}` should be `{int: number}`. `unknown & T` is always `unknown`, any characteristic T has will be discarded by the intersection.
- `any` is the union (|) of all types, including that internal one that can be anything, and yes, `unknown` too. `(any & {int: number})` should be `{int: number}`. also, `const x: any = 5 as unknown`. Union with `any` should always produce `any`.
- thoughtspile 4y agoI'm afraid you're confusing something! The intersection of all types is never, because, say, number and string don't intersect. The union of all types is unknown. any doesn't show set-like properties and yields ternary logic in clauses like any extends T, which makes it a paradox.
- bazoom42 4y agoI think you have switched union and intersection. ’Unknown’ is a type which can be anything, so it is the union of all types. ‘Never’ is the empty set of types. ‘Any’ does not really fit into a set theoretical model because it can be assigned to anything and anything can be assigned to it, so it is both a supertype of anything and a subtype of anything. Basically it just disables type checking.