如何组合 flowjs 类型定义
How to combine flowjs type definitions
如何组合以下类型定义,这样我就不必重复了?
type Lama = {|
name: string,
|};
type LamaWithHat = {|
name: string,
hat: string,
|};
已尝试使用 Interseptions,但语法似乎有误:
type LamaWithHat = {|
hat: string,
|} & Lama;
如果我们这样做怎么样
/* @flow */
type Lama = {|
name: string,
|};
type LamaWithHat = {|
...Lama,
hat: string,
|};
const a: Lama = {
name: 'rahul'
}
const b: LamaWithHat = {
name: 'rahul',
hat: 'circluar'
}
如何组合以下类型定义,这样我就不必重复了?
type Lama = {|
name: string,
|};
type LamaWithHat = {|
name: string,
hat: string,
|};
已尝试使用 Interseptions,但语法似乎有误:
type LamaWithHat = {|
hat: string,
|} & Lama;
如果我们这样做怎么样 /* @flow */
type Lama = {|
name: string,
|};
type LamaWithHat = {|
...Lama,
hat: string,
|};
const a: Lama = {
name: 'rahul'
}
const b: LamaWithHat = {
name: 'rahul',
hat: 'circluar'
}