TypeScript api response interface All In One
interface apiObj {
msg: string;
status: number;
}
interface apiRes {
data: apiObj;
// data?: T;
}
interface apiErr {
data: apiObj;
// data?: T;
}
// Service
const createData = (params = {}) => {
setIsModalLoading(true);
createMonitor(params).then(res => {
const {
msg,
status,
} = res?.data ?? {};
if(status === 200) {
message.success(`${msg}`);
onResetData();
setIsModalVisible(false);
}
}).catch(err => {
const {
status,
data: {
message: msg,
},
} = err;
if(status === 417) {
message.error(`${msg}`);
}
}).finally(() => {
setIsModalLoading(false);
});
};
refs
https://www.freecodecamp.org/news/make-typescript-easy-using-basic-ts-generics/
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!