流动型:string类型是用绳子枚举不兼容
问题描述:
为什么流不允许这样做:流动型:string类型是用绳子枚举不兼容
/* @flow */
const f1 = (p1: {[string]: string}) => undefined;
const f2 = (p2: {status: 'ok' | 'not_ok' }) => f1(p2);
有什么办法,使这项工作?
答
问题是,f1
可能会改变status
支柱。因此需要不变性。
/* @flow */
const f1 = (p1: {+[string]: string}) => undefined;
const f2 = (p2: {status: 'ok' | 'not_ok' }) => f1(p2);