Compile Angular2 ts file

前端 未结 4 460
一向
一向 2021-01-21 01:16

I\'m trying Angular2 using Typescript, but I have a problem with tsc.

This is my tsconfig.json file:

{
\"compilerOptions\": {
    \"module\": \"commonjs\         


        
4条回答
  •  無奈伤痛
    2021-01-21 01:36

    This is how I made my hello world work. Hope it helps.

    Create a tsd.json file and run tsd command, which shall download the typing and put in a typings folder

    {
      "version": "v4",
      "repo": "borisyankov/DefinitelyTyped",
      "ref": "master",
      "path": "typings",
      "bundle": "typings/tsd.d.ts",
      "installed": {
        "angular2/angular2.d.ts": {
          "commit": "212793c4be051977f73675fa9bb125d891df037a"
        },
        "angular2/router.d.ts": {
          "commit": "212793c4be051977f73675fa9bb125d891df037a"
        },
        "es6-promise/es6-promise.d.ts": {
          "commit": "35119c83fe214d18c7e370a678cd85dfcfbfa42a"
        },
        "rx/rx.d.ts": {
          "commit": "8fea426543e19e19db32eb827a02d11bdab30383"
        },
        "rx/rx-lite.d.ts": {
          "commit": "0a183cdfaf4ad480164696cd3d47e32650be8016"
        }
      }
    }
    

    Then add fileGlob in tsConfig instead of individual files

    {
        "version": "1.5.0",
        "compilerOptions": {
            "target": "es5",
            "module": "commonjs",
            "emitDecoratorMetadata": true,
            "outDir": "./dist/atom"
        },
        "filesGlob": [
            "./app/**/*.ts",
            "!./node_modules/**/*.ts"
        ]
    }
    

    You won't need _all.ts. And you can import typings in app controller

    /// 
    
    import {Component, View, bootstrap} from 'angular2/angular2';
    
    @Component({
        selector: 'my-app'
    })
    @View({
        template: `Hi`
    })
    
    class MyAppComponent 
    {   
        constructor() 
        {
        }
    } 
    
    bootstrap(MyAppComponent); 
    

提交回复
热议问题