简体   繁体   English

部分类型Flow.js

[英]Partialy type Flow.js

I have flow.js type definition as shown below: 我有flow.js类型定义,如下所示:

export type Block = {
  color: {
    primary: Color,
    secondary: Color,
  },
  font-size: '16px',
  font-weight: '500',
};

And I would like to create an object with not all properties defined and another one with all fields required. 我想创建一个对象,它没有定义所有属性,而另一个对象则具有所有必填字段。

So second one: 所以第二个:

const divv: Block = {
 ...all fields here
}

first one (just font-size): 第一个(仅字体大小):

const divv2: Block | any = {
 font-size: '17px'
}

As you can see I've used 如您所见,我已经习惯了

Block | 块| any 任何

To declare first one divv, but intellisense will hint me all divv2 properties, but it has only one of main Block type. 要声明第一个divv,但是intellisense会提示我所有divv2属性,但是它只有一个主要的Block类型。

How to do it correctly? 如何正确做?

Try $Shape 试试$ Shape

Copies the shape of the type supplied, but marks every field optional. 复制提供的类型的形状,但将每个字段都标记为可选。

So, it'll be: 因此,它将是:

const divv2: $Shape<Block> = {
  font-size: '17px'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM