Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flow.js Extend imported type

I'm trying to extend a Flow Type that I am importing from an external library like so:

import type { $Request, $Response } from 'express';


export type Req extends $Request {
  additionalField: {
    key: string
  }
};

This won't work, but I'm wondering if there is another way to accomplish this in Flow. I need a new type that inherits a previous type and has a few more properties on top of that.

like image 456
Cordon Davies Avatar asked Dec 11 '22 12:12

Cordon Davies


1 Answers

You might consider the Intersection type, which is created using the & operator.

The following should work:

type Req = $Request & {
  additionalField: {
    key: string
  }
}
like image 138
thejohnbackes Avatar answered Jan 04 '23 02:01

thejohnbackes