Skip to content

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented Aug 1, 2020

Fixes #72

@TriangularCube can you please check if this works?

@@ -1,4 +1,4 @@
import wsPlugin, { SocketStream } from '../..';
import * as wsPlugin from '../..';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ethan-Arrowood @mfpopa @fox1t can you please explain this to me?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer to @fox1t as he has a better understanding of this than I do

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked out this branch and tested with both esModuleInterop set to true and false (it's false by default). I see find no issues.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, when using "esModuleInterop": false (the default), import needs to be done like this import * as wsPlugin from '../..';. When using "esModuleInterop": true, import needs to be done like this import wsPlugin from '../..';.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works because export = syntax exports a so called namespace that is then imported by import *. Export default has to be used only in presence of .default prop on the exported object.

Copy link

@TriangularCube TriangularCube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, does work now!

@mfpopa
Copy link

mfpopa commented Aug 3, 2020

These changes work for me.

I tested with esModuleInterop set to both false and true. Repository I used for testing this: https://github.com/mfpopa/fastify-faux-modules

@mcollina mcollina merged commit 39a594d into master Aug 3, 2020
@mcollina mcollina deleted the fix-types branch August 3, 2020 09:45
@fox1t
Copy link
Member

fox1t commented Aug 6, 2020

We need to standardize import checks in our typescript tests. Different packages are exporting types in different ways, even if the JS code is the same. :/

@mcollina
Copy link
Member Author

mcollina commented Aug 6, 2020

Yes we should

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

Successfully merging this pull request may close these issues.

Importing from TS results in undefined variable

5 participants