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

Dynamic import does not respect --allowSyntheticDefaultImports #17444

Closed
aluanhaddad opened this issue Jul 27, 2017 · 3 comments
Closed

Dynamic import does not respect --allowSyntheticDefaultImports #17444

aluanhaddad opened this issue Jul 27, 2017 · 3 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Jul 27, 2017

TypeScript Version: 2.5.0-dev.20170725

Code

// A *self-contained* demonstration of the problem follows...
// --module esnext --allowSyntheticDefaultImports (or with --module system)
import('jquery').then(({default: $}) => $('div'));

Expected behavior:
The shape of the dynamically imported jquery's module namespace object includes a default member having the type JQueryStatic<HTMLElement> as it does when using the static import syntax as in

import {default as $} from 'jquery';
$('div');

under --module system or with --allowSyntheticDefaultImports

Actual behavior:

error TS2459: Type 'JQueryStatic<HTMLElement>' has no property 'default' and no string index signature.

Note that this is tricky since the expected mapping does not quite correspond to that of a static import since import('jquery').then($ => $('div')); probably should not work, but the default member should be present.

@Jessidhia
Copy link

This can be tricky as it won't behave correctly at runtime in webpack either.

I'd recommend just never using dynamic import with a commonjs module.

@aluanhaddad
Copy link
Contributor Author

I'd recommend just never using dynamic import with a commonjs module.

Do you mean that modules transpiled from ESNext to CommonJS should never use dynamic import, that modules in CommonJS format should never be imported using the construct, or both?

@Jessidhia
Copy link

Jessidhia commented Jul 29, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants