Typescript 1.5, importing ES6 modules

I'm actually learning TypeScript 1.5 and was wondering if I could import an ES6 external module?

I need to use this one (which provides the ES6 API) via my TS1.5 code ( https://www.npmjs.com/package/rtts_assert ).

Here's what I've tried:

import {rtts} from "../../node_modules/rtts_assert/es6/rtts_assert.es6";
import {rtts} from "../../node_modules/rtts_assert/es6/rtts_assert";
import * as rtts from "../../node_modules/rtts_assert/es6/rtts_assert.es6";
import * as rtts from "../../node_modules/rtts_assert/es6/rtts_assert";

      

But transpiler (TypeScript> ES5, with CommonJS) doesn't find this module

Thanks for the promotion

+3


source to share


1 answer


First, importing from node_modules using relative paths seems very suspicious to me. There must be a better solution. (Maybe import * as rtts from "rtts_assert/es6/rtts_assert.es6";

?)



Second, if you want to have ES5 code, you must use ES5 modules. Chrome can handle ES6 module, but if you want your code to work in IE9 or similar, you must pipe ES6 module to ES5. If you import a module, its code will be imported as is.

0


source







All Articles