Can a primitive value be a type in Typescript?
For instance, is this a valid type below? If it is not, how to make it valid?
export type Status = {
completed: false;
}
Can a primitive value be a type in Typescript?
For instance, is this a valid type below? If it is not, how to make it valid?
export type Status = {
completed: false;
}
Yes, they can. The TypeScript Docs show how setting a primitive literal can be used as the expected type, but using only one literal type isn't always valuable. Using your code as an example, you could use a type union to show possible literal values which could be assigned to completed:
export type Status = {
completed: false | 0 | "NO";
}