Skip to content

Enum Typed variables coming in as strings #581

@awasser-omnispear

Description

@awasser-omnispear

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.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions