I started learning Typescript couple days ago, it's been quite confusing so far, especially with modules.
I'm importing typings using npm install -s @types/knockout
, but most of the typings availlable are still written in Typescript 1.
Here is a typing definition from es6-promise package:
declare module 'es6-promise' {
var foo: typeof Promise; // Temp variable to reference Promise in local context
namespace rsvp {
export var Promise: typeof foo;
export function polyfill(): void;
}
export = rsvp;
}
Is there a way to import the default export specified as export = xxx
from typescript 2?
Yes, you can use them. Unfortunately, TypeScript has adopted a backward looking approach to ES Modules instead of a forward looking one.
export = rsvp
is not a default export.
A default export would have the form
export default rsvp;
export =
is a TypeScript CommonJS specific construct that implies assignment to the module.exports
property available of CommonJS modules.
In order to import it as the default, you will need to do two things.
"allowSyntheticDefualtImports": true
in your tsconfig.json