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

Suggestion to auto convert date value from type string to type Date #1429

Open
soapwong703 opened this issue Nov 22, 2024 · 1 comment
Open
Labels
enhancement New feature or request @kubb/plugin-client v3 Kubb v3

Comments

@soapwong703
Copy link

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;
  },
});
@soapwong703 soapwong703 added the enhancement New feature or request label Nov 22, 2024
Copy link

linear bot commented Nov 22, 2024

@soapwong703 soapwong703 changed the title Suggestion to auto convert date value from type string to type Date Suggestion to auto convert date value from type string to type Date Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request @kubb/plugin-client v3 Kubb v3
Projects
None yet
Development

No branches or pull requests

2 participants