Reputation: 667
I know a little about TypeScript which I've learned this month in a university course.
Can this denote the empty set?
type emptySet=0&1;
because when I try to assign this to any value, i.e. (boolean, number, string) I get type error.
I'm not sure what 0&1 does in typescript, in other programming languages, This denotes "false" or a bitwise operation.
Upvotes: 0
Views: 5016
Reputation: 2858
The type that accepts nothing is void
.
type emptySet = void;
let es: emptySet = null;
There is also the never
type, which doesn't accept anything, even null
.
type emptySet = never;
let es: emptySet = null; // Error
Upvotes: 0
Reputation: 2799
I'm not sure what you are trying to achieve but this is valid and would mean "empty set" as nothing can be void
type EmptySet = void[];
const empty: EmptySet = []; // valid
const notEmpty: EmptySet = [1,2,3]; // not valid
Upvotes: 1