If I have
type o = {
x: number
};
declare class ExampleClass {
x: number;
};
it would be nice if I did not have to write this twice, and somehow reuse the object type def
Syntax suggestion:
type o = {
x: number
};
declare class ExampleClass {
...o;
};
any word on this feature request? This would save my life with immutable records
This would also make extending classes much easier, if you assume classes that have static or instance methods that rely on its own schema. In our particular use case, we autogenerate class definitions from the database, but occasionally need to override them for this and that:
declare class Model<Props> {
static findOne(where: $Shape<Props>): Promise<?this>;
}
type UserProps = {|
id: number,
username: string,
email: string,
|};
declare class User<Props = UserProps> extends Model<Props> {
...UserProps, // can't do this
}
type CustomerProps = {|
...$Exact<UserProps>,
customerId: number,
|}
declare class Customer extends User<CustomerProps> {
...CustomerProps, // or this either
}
Most helpful comment
any word on this feature request? This would save my life with immutable records