【发布时间】:2018-11-26 02:44:31
【问题描述】:
我有一些基本类型正在使用一些类静态函数进行处理。另外我有一个扩展类型,所以我想编写一个扩展类,以与代码重用相同的方式处理它。
代码可以找到,但我不知道如何在这里让流程快乐。
这是一个小example:
// @flow
type Data = {
id: number
}
type ExtendedData = Data & {
name: string
}
class SomeClass {
static something(some: Data): this {
return new this(); // returns SomeClass
}
}
class SomeOtherClass extends SomeClass {
// flow: Cannot extend `SomeClass` [1] with `SomeOtherClass`
// because property `name` is missing in `Data` [2] but exists in
// object type [3] in the first argument of property `something`.
static something(some: ExtendedData): this {
return /* returns SomeOtherClass here */ super.something(some);
}
}
【问题讨论】:
标签: javascript flowtype