snowflakedb / snowflake-connector-nodejs

NodeJS driver
Apache License 2.0
120 stars 124 forks source link

SNOW-1454180: `const enum`s in TypeScript declaration file means enums cannot be accessed when `isolatedModules` TS compiler option is set #848

Closed mtlewis closed 1 month ago

mtlewis commented 3 months ago

Please answer these questions before submitting your issue. In order to accurately debug the issue this information is required. Thanks!

1. What version of NodeJS driver are you using?

1.11.0

2. What operating system and processor architecture are you using?

macOS / ARM

3. What version of NodeJS are you using?

18.16.0 / 9.5.1

4. What are the component versions in the environment (npm list)?

N/A

5.Server version:* E.g. 1.90.1

N/A (library author)

6. What did you do?

When using the newly-released first-party TypeScript declaration file, it's not possible to access the enums it provides, because they're declared as const enum. It's not recommended to use const enums in library declarations for this reason.

You can see this issue in this TypeScript playground: https://www.typescriptlang.org/play/?isolatedModules=true#code/JYWwDg9gTgLgBAZwHYQO4DMA2BDA1gUwBo4BvOAGQgHNz8A3fTOAXznSghDgHJk0s8+ALQIAJrm4BuAFDSA9HLgAxbMEwI4qABb4kcYAgg4Y+UQFkIogK6Z8Gg4nzwYEODChX8+vTAQBjCCR0YCppPgwcAgA6AKCQqyh8AAoyTGpaBkwALgp0+kYogHUAQQAlADkWAEoZeUVizFRsAE8NVGhcBDCUCMEYwOCqBOTUvMyc7hKK7jhsDUoafKZmGqA

7. What did you expect to see?

No errors produced by this line, even if isolatedModules is turned on in tsconfig.

snowflake.configure({ logLevel: LogLevel.WARN });

8. Can you set logging to DEBUG and collect the logs?

N/A

9. What is your Snowflake account identifier, if any? (Optional)

N/A

sfc-gh-dszmolka commented 3 months ago

hi and thank you for reporting this - taking a look. would disabling isolatedModules be a viable option until we sort this out ?

mtlewis commented 3 months ago

hi and thank you for reporting this - taking a look. would disabling isolatedModules be a viable option until we sort this out ?

Hi David - no problem, and thanks for the quick response. It's recommended for library authors to always set isolatedModules to true to ensure flexibility for consumers of the library. As such, disabling this flag won't be practical for us. The workaround in the playground link above is fine (snowflake.configure({ logLevel: 'WARN' as LogLevel })) for now, though I would note that it won't catch typos in LogLevel strings (i.e. logLevel: 'WRAN' doesn't produce an error.

sfc-gh-dszmolka commented 3 months ago

okay, got you MT and thank you for the additional clarification. Guess we have no other option than convert these to export enum (which is quite unfortunate because it will require a driver release, which just happened literally couple hours ago, so probably will happen only in the next release cycle, end of June)

mtlewis commented 3 months ago

Makes sense, thanks very much! We'll use that workaround for now.

sfc-gh-dszmolka commented 3 months ago

Will be addressed in PR https://github.com/snowflakedb/snowflake-connector-nodejs/pull/852

sfc-gh-dszmolka commented 2 months ago

PR https://github.com/snowflakedb/snowflake-connector-nodejs/pull/852 merged and will be part of the next upcoming release (usually happens at the end of the month)

sfc-gh-dszmolka commented 1 month ago

released with Snowflake Node.JS driver v1.12.0