最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Flow.js Extend imported type - Stack Overflow

programmeradmin0浏览0评论

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 acplish this in Flow. I need a new type that inherits a previous type and has a few more properties on top of that.

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 acplish this in Flow. I need a new type that inherits a previous type and has a few more properties on top of that.

Share Improve this question edited Mar 23, 2017 at 18:58 Nat Mote 4,08619 silver badges30 bronze badges asked Mar 22, 2017 at 20:33 Cordon DaviesCordon Davies 2113 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 13

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

The following should work:

type Req = $Request & {
  additionalField: {
    key: string
  }
}
发布评论

评论列表(0)

  1. 暂无评论