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

Invoice field date and dueDate not matching typescript definition #487

Open
gjuchault opened this issue Feb 1, 2021 · 2 comments
Open

Comments

@gjuchault
Copy link

gjuchault commented Feb 1, 2021

SDK you're using (please complete the following information):

  • Version: 4.9.1

Describe the bug

The Invoice model in TypeScript is not matching the actual invoice entities returned by the SDK.

In the typescript definition:

    /**
    * Date invoice was issued – YYYY-MM-DD. If the Date element is not specified it will default to the current date based on the timezone setting of the organisation
    */
    'date'?: string;
    /**
    * Date invoice is due – YYYY-MM-DD
    */
    'dueDate'?: string;

If you look to the result of createInvoices (Date instance):
image

To Reproduce
Steps to reproduce the behavior:

  1. Do a getInvoice or createInvoices call

Expected behavior

  • date field to be a string
@jamesrusso
Copy link

I am seeing the same issue on BankTransaction. Any updates or workarounds?

@mbyrne00
Copy link

mbyrne00 commented Jan 19, 2022

Oh man ... this is so bad. I just got caught with this today. We had luckily been handling this because we were previously using moment to convert it and by fluke the "all purpose" constructor of moment just handled it. Finally switched to luxon and saw this.

The typing is wrong, the date format of the API is wrong (it's the old .NET format in the underlying api but the JSDoc says YYYY-MM-DD). This really needs update and not sure why it's been left so long without answering it. I've had to write a generic util to parse xero dates as string | Date since I have no confidence in what the library is doing.

I can definitely see in the deserialize function that it's creating a Date

    static deserialize(data, type) {
        // polymorphism may change the actual type.
        type = ObjectSerializer.findCorrectType(data, type);
        if (data == undefined) {
            return data;
        }
        else if (primitives.indexOf(type.toLowerCase()) !== -1) {
            if (type === "string" && data.toString().substring(0, 6) === "/Date(") {
                return this.deserializeDateFormats(type, data); // For MS dates that are of type 'string'
            }
            else {
                return data;
            }
        }
  ....

Even though the type map specifies it as string, the function sees it starts with /Date( and converts it to a Date

@SerKnight - are you able to assist with this one? I think it's fine that they are converted to Date ... I think the expected behaviour is not to change it to string but to update the typings to be correct. Seems like all date fields are affected in all responses.

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

3 participants