TypeScript Version: 2.1.4 / tried with current nightly yesterday
Linked issues :
rollup/rollup#1156
infernojs/inferno#596
Code
Inferno exports something like:
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('./inferno')) :
typeof define === 'function' && define.amd ? define(['exports', 'inferno'], factory) :(factory((global.Inferno = global.Inferno || {}),global.inferno));
In typescript, it is export default class Component{}.
When imported, you'll expect this to work:
import createElement from 'inferno-create-element'
import Component from 'inferno-component'
console.log(createElement)
console.log(Component)
But those will both be undefined because the typescript compiler exports something like:
console.log(inferno_create_element_1.default);
console.log(inferno_component_1.default);
I also tried to import as:
import * as createElement from 'inferno-create-element'
import * as Component from 'inferno-component'
Which does bring back the correct values, except their signature is now wrong and you can not use them as intended (for example class extend Component).
Reproduction
Here is a reproduction repository:
https://github.com/soyuka/repro-default-export
Clone and run bash init.sh.
Note that:
- Inferno creator says typescript fixed this issue (I tried latest + next without success)
- Rollup (which is used by inferno for umd bundle) says it might be a typescript issue
- There is no difference with or without webpack, therefore it's definitely not a webpack issue
To me it's probably that typescript always expect a default key, which is why I made a proposal to add the following to rollup:
//add this and everything works:
if (typeof module !== 'undefined') {
module.exports.default = module.exports
}
Would you be able to give me some details about the typescript expected behavior? Is this a rollup issue or a typescript one?
Thanks!
TypeScript Version: 2.1.4 / tried with current nightly yesterday
Linked issues :
rollup/rollup#1156
infernojs/inferno#596
Code
Inferno exports something like:
In typescript, it is
export default class Component{}.When imported, you'll expect this to work:
But those will both be undefined because the typescript compiler exports something like:
I also tried to import as:
Which does bring back the correct values, except their signature is now wrong and you can not use them as intended (for example
class extend Component).Reproduction
Here is a reproduction repository:
https://github.com/soyuka/repro-default-export
Clone and run
bash init.sh.Note that:
To me it's probably that typescript always expect a default key, which is why I made a proposal to add the following to rollup:
Would you be able to give me some details about the typescript expected behavior? Is this a rollup issue or a typescript one?
Thanks!