Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Const enum pitfalls... #6

Closed
udsv-user opened this issue Nov 19, 2023 · 6 comments
Closed

Const enum pitfalls... #6

udsv-user opened this issue Nov 19, 2023 · 6 comments

Comments

@udsv-user
Copy link

Use of const enum in uDSV.d.ts is problematic as described here. Please consider replacing it.

@leeoniya
Copy link
Owner

leeoniya commented Nov 19, 2023

sooo, since this is a JS codebase, changing to regular enum in the .d.ts file is inconsequential.

the question becomes if i ever want to migrate to TS if this change would prevent inlining, which i want to retain.

i guess this is the answer:

image

the build step they link to is in a Gulpfile, so will need to be different for a Rollup/TS setup, but should be straightforward with something like https://www.npmjs.com/package/@rollup/plugin-replace

@udsv-user
Copy link
Author

udsv-user commented Nov 20, 2023

@leeoniya Thanks for your comments. I should have explained my issue in more detail and maybe you would have a suggestion to fix it. But I did not get a chance to create an MRE before. I think I have something now that should be pretty easy to reproduce.

Let's say I create a simple React app that uses Typescript using:

npx create-react-app my-app --template typescript

Now I want to use your excellent udsv library with it so I add it:

npm i udsv

Then I add the following two simple lines near the top of App.tsx:

import { SchemaColumnType } from 'udsv';
const foo = SchemaColumnType.Number;

This produces the following error warning on the second line above:

TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

So, const enums cannot be used with isolatedModules. Fine, so I will disable isolatedModules in tsconfig.json which eliminates this warning but does not solve the problem.

    ...
    isolatedModules": false
    ...

Now I get the following error message(s):

udsv__WEBPACK_IMPORTED_MODULE_3__.SchemaColumnType is undefined
...
export 'SchemaColumnType' (imported as 'SchemaColumnType') was not found in 'udsv' (possible exports: inferSchema, initParser)

Any thoughts?

@udsv-user
Copy link
Author

udsv-user commented Nov 20, 2023

Well phooey. Enums inside .d.ts files are of no use in such cases (as you already pointed out in your comments as this is a JS codebase).

@leeoniya
Copy link
Owner

leeoniya commented Nov 20, 2023

can you check if the latest commit fixes it?

update your dependency in package.json with the github commit link:

"udsv": "leeoniya/uDSV#0c191e8a80e7b0d78bfd0bf6ec37dc576deefbde

then run npm install again

@udsv-user
Copy link
Author

Thanks for the update, @leeoniya. However, unfortunately, I am getting the same error message (I tried the same update in my own local copy earlier and it did not work).

I am fairly convinced after reading this that having the enum just in the .d.ts file will not work. So, please don't waste any more of your (valuable) time on this issue. Someday, if you decide to switch to Typescript, I will drop by and help out.

@udsv-user
Copy link
Author

A few other discussions that you might find useful in this context:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants