【发布时间】:2022-11-07 14:47:11
【问题描述】:
对于下面的示例,为什么类型转换在 Flowtypes 中不起作用?理想的做法应该是什么?
type typeA = {
name: 'ben' | 'ken',
};
type typeB = {
name: string,
};
const objA: typeA = { name: 'ben' };
const objB: typeB = objA;
它给出了错误
Cannot assign `objA` to `objB` because in property `name`: Either string [1] is incompatible with string literal `ben` [2]. Or string [1] is incompatible with string literal `ken` [3].
但是,对于打字稿来说,这很好。
【问题讨论】:
标签: javascript flowtype