-
Notifications
You must be signed in to change notification settings - Fork 16
Description
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.