在通用声明中破坏的用途是什么?
破坏可能是错误的术语...
在我正在工作的代码库中找到了这一点。这令人困惑。
await apolloClient
.query<{ Workorder: Workorder }>({
query: WORKORDER_QUERY,
variables: { uuid: id },
})
我看不到{workorder:workorder}
的点。这里发生了什么?该vs .query&lt; workorder&gt;
的值是什么?
Workorder
是一个大约30个属性的接口。
Destructuring might be the wrong term...
Found this in the codebase I'm working in. It's perplexing.
await apolloClient
.query<{ Workorder: Workorder }>({
query: WORKORDER_QUERY,
variables: { uuid: id },
})
I don't see the point of { Workorder: Workorder }
. What is happening here? What is the value of that vs .query<Workorder>
?
Workorder
is an interface with about 30 properties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是破坏性的。这只是意味着要传递的类型参数是具有工作表属性的对象,并且该属性的值是工作派。
例如,给定的:
结果
是类型:而如果执行结果,则类型为类型,而
结果现在是类型:
不是
.query 做同样的事情,但这会让您了解区别是什么。执行
&lt; {workorder:workorder}&gt;
只需将工作端包装在对象中,然后将其作为类型参数传递。It's not destructuring. It just means that the type argument being passed is an object with a Workorder property, and that the value for that property is a Workorder.
For example, given:
where the type parameter is the same type that's returned, the
result
is of type:Whereas if you do
the result is now of the type:
Not that
.query
does the same thing, but that'll give you an idea of what the difference is. Doing<{ Workorder: Workorder }>
just wraps the Workorder in an object and passes it as a type parameter.