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

[TypeScript] Unable to use a plugin with typescript #149

Closed
Losses opened this issue Aug 7, 2020 · 3 comments
Closed

[TypeScript] Unable to use a plugin with typescript #149

Losses opened this issue Aug 7, 2020 · 3 comments

Comments

@Losses
Copy link

Losses commented Aug 7, 2020

Just doing similar thing to demo code to add a new plugin:

image

And got:
image

Maybe there're some thong wrong with the TypeScript definition

@pimterry
Copy link
Owner

You're right, I can reproduce this, and it's incorrect, but I have no idea why it's happening. It's definitely not marked as a read-only property explicitly.

Any suggestions? Happy to take hints or PRs to get this fixed.

@pimterry
Copy link
Owner

Ok, I think I know the cause of this. The problem is that TypeScript assumes that import * as ... module export properties are always readonly. That's not true in many real environments, but I think it's required by the ES6 spec, and so will be true in native ES6 environments.

Fortunately, this is possible if you're using a default import. That was only supported in TS if you had esModuleInterop enabled, but in dcc07d1 I've now added a .default property on the root object, which makes this possible all the time.

I'll release this at 1.7.0 in a moment. To use it, just change from:

import * as log from 'loglevel';

to

import log from 'loglevel';

Both are supported in general, but to make the types happy when assigning to methodFactory in TypeScript, the latter must be used.

@ELeigh91
Copy link

Worked for me using "allowUmdGlobalAccess": true in the tsconfig.json

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