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

How to import single function for Node / TypeScript #286

Open
ammulder opened this issue Mar 23, 2023 · 8 comments
Open

How to import single function for Node / TypeScript #286

ammulder opened this issue Mar 23, 2023 · 8 comments

Comments

@ammulder
Copy link

I'm using bwip-js 3.3.0 and @types/bwip-js 3.2.0 and generating code128 barcodes on Node 18 (AWS Lambda).

I see the documentation says:

The ESM also facilitates bundler tree-shaking by providing the individual encoders as named exports. Each exported encoder functions identically to bwipjs.toBuffer().

But I can't figure out how to get this sort of thing to work from TypeScript:

import { code128 } from 'bwip-js';
...
const buffer = await code128({...});

It doesn't seem to be a valid import. I tried marking up the TypeScript type definitions to declare code128 the same as toBuffer and at runtime got an error that code128 is not a function.

Is this meant to work? If so, any tips?

@metafloor
Copy link
Owner

This appears to be a typescript-specific issue, and I do not have experience with the typescript development environment. The ESM tree-shaking is part of this project's test framework, so I know it is working. The test cases uses webpack. Not sure what typescript uses but I think the actual problem is the typescript definition/type file, and I have zero understanding of how that works...

@ammulder
Copy link
Author

OK, I'll take it up on DefinitelyTyped I guess, thanks.

@metafloor
Copy link
Owner

Have you found a solution to this issue?

@ammulder
Copy link
Author

Sadly, I fell victim to laziness and just imported *

@joewestcott
Copy link

I think it's safe to assume this is a DefinitelyTyped issue, as it doesn't (yet) have the individual barcode symbologies configured as exports.
See here

@metafloor
Copy link
Owner

I would like to include an updated/improved copy of the DefinitelyTyped schema as part of the bwip-js project but am unsure of the etiquette. For those who use typescript, it considered ok to copy the schema (maintaining the current attributions) and make the changes to the project's copy?

@joewestcott
Copy link

DefinitelyTyped is intended as a fallback for when the project doesn't export the type definitions itself. I'm sure every TS developer would prefer the types in the source repo as it would mean TS support without an additional install. Generally the DefinitelyTyped defs would be removed once this happens.

For those who use typescript, it considered ok to copy the schema (maintaining the current attributions) and make the changes to the project's copy?

Assuming the licences are compatible I'd say that's fine.

@metafloor
Copy link
Owner

Type files are now available in version 4. You can read about them here #299 (comment).

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

3 participants