-
Notifications
You must be signed in to change notification settings - Fork 553
Description
The TypeScript team largely regards const enums as a design mistake because it causes so many downstream issues with libraries.
One issue I've personally run into with Fluid though relates to the fact that they don't work with the single-file at a time compilation model that lots of tools use including
- TypeScript's
transpileModule
(which is surfaced by ts-loader and awesome-typescript-loader) - Babel
- esbuild
- swc
As an example, if you try to write a line of code like
import { IMergeTreeOp, MergeTreeDeltaType } from "@fluidframework/mergetree";
function mergeymerge(op: IMergeTreeOp) {
if (op.type === MergeTreeDeltaType.INSERT) {
// ...
}
}
The code will fail to run correctly under several of these modes, and you will get an error under --isolatedModules
.
One way to alleviate issues with const enums is to at least compile the TypeScript code with --preserveConstEnums
, so that these exports exist at runtime or bundle-time. These can increase your bundle size if you're not using TypeScript, but it will make running the code more accessible.