2016-10-23 5 views
0

TSで使用するes6モジュールの使い方を教えてください。 例:typescript 2でどのようにes6モジュールを使用するのかわかりません2

class1.tsにimport ext.classを試してみます。

class1.ts 
import ExtClass from "./ext.class"; 
class Class1 { 
    constructor(){ 
     console.log(new ExtClass().title) 
     console.log("Work") 
    } 
} 
new Class1(); 

その輸出クラス

ext.class.ts 
class ExtClass { 
    public title: string = "ExtClass work"; 
} 
export default ExtClass 

package.json 
{ 
    "name": "ts_def", 
    "version": "0.0.0", 
    "license": "MIT", 
    "private": true, 
    "scripts": { 
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ", 
    "lite": "lite-server" 
    }, 
    "dependencies": { 
    "core-js": "^2.4.1", 
    "ts-helpers": "^1.1.1" 
    }, 
    "devDependencies": { 
    "@types/jasmine": "^2.2.30", 
    "@types/node": "^6.0.42", 
    "codelyzer": "~0.0.26", 
    "ts-node": "1.2.1", 
    "tslint": "3.13.0", 
    "typescript": "2.0.2", 
    "concurrently": "^3.0.0", 
    "lite-server": "^2.2.2" 
    } 
} 
tsconfig.json 
{ 
    "compilerOptions": { 
    "declaration": false, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "lib": ["es6", "dom"], 
    "mapRoot": "./", 
    "module": "es6", 
    "moduleResolution": "node", 
    "outDir": "../dist/out-tsc", 
    "sourceMap": true, 
    "target": "es6", 
    "typeRoots": [ 
     "../node_modules/@types" 
    ] 
    } 
} 

結果では、私はCLIおよびブラウザで予期しないトークンのインポートを受け取ります。どうか、私に言います、何が間違っていますか?

答えて

0

これで、typescriptからes6コードを出力しています。今は、ES5コードにそれ以上の移行を計画しない限り、これは有用ではありません。

通常、ウェイモジュールを使用するには、コードをES5に移し、ES6モジュールをESSモジュール定義(たとえば、systemjsモジュール)に変換し、実行時にSystemJSのようなモジュールローダーを使用してロードします。

関連する問題