0

How can I combine the following type definitions, so I dont have to repeat myself?

type Lama = {|
name: string,
|};

type LamaWithHat = {|
name: string,
hat: string,
|};

Tried using Interseptions but appearently the syntax might be wrong:

type LamaWithHat = {|
hat: string,
|} & Lama;
yN.
  • 1,847
  • 5
  • 30
  • 47

1 Answers1

1

How about if we do this /* @flow */

type Lama = {|
name: string,
|};

type LamaWithHat = {|
...Lama,
hat: string,
|};

const a: Lama = {
    name: 'rahul'
}

const b: LamaWithHat = {
    name: 'rahul',
    hat: 'circluar'
}

test this code here https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVAXAngBwKZgAyAhgLbFgC8YA3gD6oB2ZeAXGAM4YBOAlowHMANKjoBfANzps+ImWIB1XhgAWACWIYqtBgDp9JciJWb2XPoJHipqAMZxGXMMXaGK1GqjDewzUmzAAcm5iFQBXGEDUMXR7Ry0AI1d5JVUNLQ8vHz8A4NCIwJEfMBMMdkDbXm5bGDDibiixIA

Rahul Rana
  • 455
  • 2
  • 7