我想提取一个嵌套类型,如下面的代码所示。有没有办法对可为空的字段执行此操作?
type Query = { a: { b?: { c: string } };
type c = Query['a']['b']['c'];
Property 'c' does not exist on type '{ c: string; } | undefined'.ts(2339)
最佳答案
type Query = { a: { b?: { c: string } } };
type foo = NonNullable<Query['a']['b']>['c'];
关于typescript - 如何访问可为空的 typescript 嵌套类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74204667/