generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Labels
Description
What is the problem this feature would solve?
Currently in the @kubb/plugin-ts, it supports to generate Date value type to Date
with the config dateType: true
, but the actual value returned is still string
type, as the result we need to manually convert the value to match its type with a custom client.
External documents/projects?
No response
What is the feature you are proposing to solve the problem?
I suggest adding an config to handle the value conversion.
What alternatives have you considered?
Currently we need to handle it with a custom client with manual checking on key and content-type.
const dateKeyRegex = /date$/i;
export const axiosInstance = axios.create({
transformResponse: (data, headers) => {
if (headers["content-type"] === "application/json") {
return JSON.parse(data, (key, value) =>
dateKeyRegex.test(key) ? new Date(value) : value,
);
}
return data;
},
});