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

Difficult to use in ES6 module package. #878

Closed
peeveen opened this issue Jul 21, 2023 · 10 comments
Closed

Difficult to use in ES6 module package. #878

peeveen opened this issue Jul 21, 2023 · 10 comments
Labels

Comments

@peeveen
Copy link
Contributor

peeveen commented Jul 21, 2023

In my TypeScript project, this code works ok ...

import Aedes from "aedes"
const aedes: Aedes = new Aedes();

... until I add "type": "module" to my package.json.
It now shows the errors Cannot use namespace 'Aedes' as a type and the expression is not constructable.

This is only workaround I could figure out:

const aedes: Aedes.default = Aedes.createBroker()
@peeveen peeveen added the bug label Jul 21, 2023
@robertsLando
Copy link
Member

Please consider opening a PR to fix this issue

@hjdhjd
Copy link
Contributor

hjdhjd commented Nov 23, 2023

As I mentioned here, and may be useful for others...this PR breaks TypeScript in straightforward use cases with simple tsconfigs.

I would suggest this PR is reverted or updated to correct the errors. Removing the code introduced in the PR fixes the issue.

@robertsLando
Copy link
Member

@hjdhjd Would you like to submit a PR to fix that?

@hjdhjd
Copy link
Contributor

hjdhjd commented Nov 23, 2023

Happy to, but it would be to revert the changes made in the prior PR. If you're good with that, I will be happy to submit it.

@robertsLando
Copy link
Member

isn't there a way to keep the changes and fix what's not working?

@hjdhjd
Copy link
Contributor

hjdhjd commented Nov 24, 2023

The changes are the problem - they shouldn't be there in the first place because the prior code was correct. Here's a helpful stackoverflow answer: https://stackoverflow.com/questions/55506545/export-assignment-and-exporting-types-in-typescript-ambient-module

In experimenting with aedes for a couple of days it seems many of the TypeScript typings are either incorrect or ambiguously defined. I'll take a closer look all around and put together a PR to correct some of them.

@robertsLando
Copy link
Member

robertsLando commented Nov 24, 2023

@hjdhjd I agree types can be imrpved a lot, go for the PR I will take a look 👍🏼

@hjdhjd
Copy link
Contributor

hjdhjd commented Nov 26, 2023

@hjdhjd I agree types can be imrpved a lot, go for the PR I will take a look 👍🏼

Submitted.

@getlarge
Copy link
Member

I just encountered a similar issue when trying to import in Typescript a module exported with module.exports = TheModule.
Since TheModule (in that case, ClinicBubbleprof from @clinic/bubbleprof) has no type definitions, I created them and the correct way to export it was by using export = TheModule.
Then in the TS file, the import was done with import TheModule = require('path-to-the-module');
To keep on using the import X from x syntax, i had to set esModuleInterop=true in compilerOptions.

Reference

@robertsLando
Copy link
Member

@getlarge This should have been fixed by #918

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

No branches or pull requests

4 participants