TypeScript - 错误 TS1146:需要声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34735530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:12:43  来源:igfitidea点击:

TypeScript - error TS1146: Declaration expected

javascriptangulartypescript

提问by Leon Gaban

I got the latest TypeScriptvia npm (npm install -g typescript)

我通过 npm ( )获得了最新的TypeScriptnpm install -g typescript

Version 1.7.5

Version 1.7.5

When I run the typescript compile command on my file: tsc app.component.ts --module system

当我在我的文件上运行 typescript compile 命令时: 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?

有谁知道这个错误是什么意思?

采纳答案by kennypu

you need to import Viewfrom angular2/coreas well:

你需要进口Viewangular2/core,以及:

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

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

回答by luhuang

Try this

试试这个

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