Skip to content

DefaultEndOfLine enum not accessible in Javacript API #2

@vassudanagunta

Description

@vassudanagunta

The following line from the README described API works in Typescript but not in Javascript or Coffeescript.

Piece Tree exports the DefaultEndOfLine enum as it is necessary for the API. Per the README:

const pieceTree = pieceTreeFactory.create(DefaultEndOfLine.LF);

This works in Typescript, but in plain Javascript or Coffeescript one gets the following:

TypeError: Cannot read property 'LF' of undefined`

I looked into it and learned that the Typescript compiler declares a const enum in the TS declaration files, but does not generate any JS code for it -- as constants they are completely erased (replaced with hardcoded underlying values) at compile time. Hence the error for any client that doesn't look at the TS declaration files, e.g. Javascript, Coffeescript, etc.

Removing the const keyword eliminates the error, but now there is a level of indirection when accessing Typescript values. Not sure what the ideal solution is.

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