Is it possible to define compulsory fields (without defaults)?
salimfadhley opened this issue · comments
Salim Fadhley commented
I want to define a simple Record in which all fields are compulsory. This code complies fine:
import Record from 'dataclass'
class Location extends Record<Location> {
name: string = '';
address: string = '';
}
But what I'd really like to do is this:
import Record from 'dataclass'
class Location extends Record<Location> {
name: string;
address: string;
}
Where I don't provide a default value to my compulsory fields. Can this be done?
spockoyno commented
This definition would be very useful eg to avoid invalid dataclass instances.
Oleksii commented
In JavaScript it's not possible because Babel removes class fields with no value as "Flow type annotation". The same happens in TypeScript. This means, there are no "keys" to operate in runtime.