How to make it possible to use Typescript with SystemJS and Angular?

前端 未结 3 1619
再見小時候
再見小時候 2021-01-12 00:44

I\'m trying to make SystemJS work with Typescript, but they seem to conflict with each other.

How can I take advantage of the autoloading from System.js without it

3条回答
  •  离开以前
    2021-01-12 01:37

    In TypeScript, you would write the following import statement...

    import dep = require('dep');
    
    console.log(dep);
    

    When you compile, you pass the module flag:

    tsc --module commonjs app.ts
    

    This tells TypeScript to target CommonJS style modules (it can also target AMD if needed - SystemJS supports both styles of syntax).

    The output looks like this:

    var dep = require('dep');
    
    console.log(dep);
    

    This output is analogous to the following example from the SystemJS documentation.

    // library resource
    var $ = require('jquery'); // -> /lib/jquery.js
    
    // format detected automatically
    console.log('loaded CommonJS');
    

    If you need more help, you can ask a question and include specific examples that demonstrate the issue and we will be able to give more specific advice.

提交回复
热议问题