Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除在TypeScript或Flow中未定义的继承类型的联合类型细化_Typescript_Flowtype - Fatal编程技术网

如何删除在TypeScript或Flow中未定义的继承类型的联合类型细化

如何删除在TypeScript或Flow中未定义的继承类型的联合类型细化,typescript,flowtype,Typescript,Flowtype,我有一个从库中继承并导入的类型,我想知道如何删除它对null或未定义值的允许 type Foo = { baz: string } // Bar type is inherited and I would like to kill the union with undefined so I expect foo to never be falsey. type Bar = { foo?: Foo } const bar: Bar = {foo: {baz: 'baz'}}; /

我有一个从库中继承并导入的类型,我想知道如何删除它对null或未定义值的允许

type Foo = {
    baz: string
}

// Bar type is inherited and I would like to kill the union with undefined so I expect foo to never be falsey.
type Bar = {
    foo?: Foo
}
const bar: Bar = {foo: {baz: 'baz'}};
// this destructuring issues an error because it allows for the possibility of it being undefined and undefined can't be destructured. And I can't conditionally exit since I'm using React hooks and I'd be violating the hooks should not be used conditionally rule
const {baz} = bar.foo;

内置的typescript中有一个实用程序类型,名为,您可以像下面那样使用它

类型Foo={
baz:字符串
}
类型栏={
福?:福
}
StrictBar类型=必需
//类型StrictBar={foo:foo}

太棒了!是否有类似的流动工具?这个问题实际上是一个流程问题,我希望有一个与工具无关的解决方案。再次感谢!在看到链接后,我在这里看到了流的等价物: