MariaDB Typescript enum fix

Recently I was looking through the github issues for the MariaDB nodejs connector project for some low hanging fruit. I came across issue 347. This is something that is common in projects written in Javascript that are consumed via a Typescript project. The crux of the problem is the difference between a const enum and an enum.

When compiled (transpiled?), a const enum has it's values inlined.

Const enums can only use constant enum expressions and unlike regular enums they are completely removed during compilation. Const enum members are inlined at use sites.

In this particular case the issue arises as MariaDB changed a const enum to an enum. This prevented the enum from being inlined during compilation of package consumers from Typescript to Javascript. Which as the Typescript docs forewarn, may have unexpected side effects.

The solution that I came across was to export the Javascript object that contained the relevant field type values. This meant that when imported via a downstream Typescript package, the Types object contained the relevant values.

The fix itself was small, see pull request 355. But I found the issue to be interesting, as what looked like a subtle change had an unexpected impact. I'd say this is questionable DX. I don't fully understand the need to have an enum and const enum. Especially as the usage of one over the other may, as the Typescript docs say, lead to "surprising bugs".

Until next time,

- Brian