Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load System.js modules with TypeScript?

I'm trying to get TypeScript working with the default Aurelia skeleton, which is based on System.JS as a loader.

I'm having trouble getting TypeScript to accept module imports. I renamed one of the skeleton files, "nav-bar.js" to "nav-bar.ts" to see if I could convert the example into TypeScript. The code results in a compiler error: "Error:(5, 24) TS2307: Cannot find external module 'aurelia-framework'."

import {bindable} from "aurelia-framework";

export class NavBar {
  //noinspection ES6Validation
  @bindable router = null;
}

How can I get TypeScript to see the aurelia-framework as a valid import? There's a file in the root of the project called config.js that seems to describe the specific location of "aurelia-framework" but TypeScript doesn't know how to load it.

Thanks in advance for your help.

like image 666
Greg Sherman Avatar asked Jun 12 '15 05:06

Greg Sherman


People also ask

Does TypeScript support CommonJS?

TypeScript supports the following 4 Modules: commonjs, amd, system and umd.

Can TypeScript import JS?

The allowJs setting allows JavaScript files to be imported inside your TypeScript files.To import a JavaScript file into a TypeScript file: Set allowJs to true in your tsconfig. json file. Import named exports as import { getEmployee } from './employee' .


1 Answers

You may want to use d.ts definition files for registration with TypeScript Definitely Typed registry for use with tsd package manager. You can find different implementations on github, for example here or here. Also this tutorial might be useful.

like image 104
Max Brodin Avatar answered Oct 10 '22 22:10

Max Brodin