流动型:string类型是用绳子枚举不兼容

问题描述:

为什么流不允许这样做:流动型:string类型是用绳子枚举不兼容

/* @flow */ 

const f1 = (p1: {[string]: string}) => undefined; 
const f2 = (p2: {status: 'ok' | 'not_ok' }) => f1(p2); 

Flowtype repl

有什么办法,使这项工作?

问题是,f1可能会改变status支柱。因此需要不变性。

solution

/* @flow */ 

const f1 = (p1: {+[string]: string}) => undefined; 
const f2 = (p2: {status: 'ok' | 'not_ok' }) => f1(p2);