简体   繁体   English

TypeScript - 错误 TS1146:需要声明

[英]TypeScript - error TS1146: Declaration expected

I got the latest TypeScript via npm ( npm install -g typescript )我通过 npm ( npm install -g typescript ) 获得了最新的TypeScript

Version 1.7.5

When I run the typescript compile command on my file: tsc app.component.ts --module system当我在我的文件上运行打字稿编译命令时: tsc app.component.ts --module system

I get the following error: app.component.ts(15,7): error TS1146: Declaration expected.我收到以下错误: app.component.ts(15,7): error TS1146: Declaration expected.

import {Component} from 'angular2/core';

    @Component({
        selector: 'my-app',
        // template: '<h1>My title: {{title}}</h1> <h2>Hardcoded h2</h2>'
    })
    @View({ // <- line 7
        templateUrl: '/templates/home.html',
        directives: []
    })
    .Class({
        constructor: function() {

        }
    }); // <- line 15

export class AppComponent {
    title = "My First Angular 2 App";
}

Anyone know what this error means?有人知道这个错误是什么意思吗?

Try this试试这个

import { Component } from '@angular/core';

you need to import View from angular2/core as well:您还需要从angular2/core导入View

import {Component, View} from 'angular2/core';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM