Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【小白 请教接口 ts使用】 #46

Closed
chenxu-javascript opened this issue Oct 15, 2020 · 3 comments
Closed

【小白 请教接口 ts使用】 #46

chenxu-javascript opened this issue Oct 15, 2020 · 3 comments

Comments

@chenxu-javascript
Copy link

大佬, 请教一哈, 从yai拉去返回的接口是完整的。 比如说 { result: { code: 0, status: 'success' }, data: [{ title: '业务数据' }]}
这个时候通过泛型 请求接口axios 是能获取到提示类型的。

想请问一哈, 业务使用的时候, 只需要业务数据定义的ts interface, 需要剔除返回状态吗, 实现共用。
不知道大佬是怎么在项目中实现的此类业务场景的

@fjc0k
Copy link
Owner

fjc0k commented Oct 15, 2020

image

@chenxu-javascript
Copy link
Author

谢谢大佬, 我想再请问一哈,
dataKey是统一配置。
如果每个接口我期望返回的数据不一致, 应该怎么配置。比如说a 接口 { result: { code: 0, status: 'success' }, data: [{ title: '业务数据' }]} b接口我期望获取 { result: { code: 0, status: 'success' }, data: { table: [{ table 业务数据 }], total: 10 }。

dataKey在这种情况就不能完全满足。

目前我们的解决方案是根据yapi-to-typescript 自动生成 然后copy 出去组装对应业务代码。
再次感谢大佬

@fjc0k
Copy link
Owner

fjc0k commented Oct 19, 2020

dataKey 可以在服务器级别、项目级别、分类级别配置,只要保证某个分类下的返回结果一样,就行了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants