xero-node icon indicating copy to clipboard operation
xero-node copied to clipboard

Enum Typed variables coming in as strings

Open awasser-omnispear opened this issue 2 years ago • 1 comments

I am using TypeScript and the accountingApi.getReportProfitAndLoss endpoint. The response from of this endpoint has some enum types. RowType being one of them, as seen below. https://github.com/XeroAPI/xero-node/blob/bfcaf1c3426c3387b19b3eee959fd4af17b83d8d/src/gen/model/accounting/reportRow.ts#L5

However, the actual data coming down is not an Enum, it is actually a string. This causes an error when comparing the value of the data to the enum. I.E. row.rowType == RowType.Header will always be false. row.rowType == 'Header' will work, but TypeScript indicates this as an error. I should note, that this only affects the TypeScript typing. JavaScript works perfectly fine, since it does not enforce any types.

A workaround would be to use row.rowType.toString() == 'Header'. Since rowType comes in as a string anyway, calling toString() effectively does nothing, except to satisfy TypeScript.

I would like to see the row.rowType == RowType.Header code fragment work correctly for TypeScript users.

awasser-omnispear avatar Mar 31 '22 16:03 awasser-omnispear

Hrmmm ... another typescript issue. Just heads up that the dates are also incorrectly typed, format incorrectly documented and plain wrong and the team have simply ignored this blatant bug since Feb 2021. https://github.com/XeroAPI/xero-node/issues/487#issuecomment-1016151415

mbyrne00 avatar Jun 03 '22 03:06 mbyrne00