Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - error TS1146: Declaration expected

I got the latest TypeScript via npm (npm install -g typescript)

Version 1.7.5

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

I get the following error: 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?

like image 809
Leon Gaban Avatar asked Mar 13 '23 15:03

Leon Gaban


2 Answers

Try this

import { Component } from '@angular/core';
like image 165
luhuang Avatar answered Mar 16 '23 11:03

luhuang


you need to import View from angular2/core as well:

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

like image 24
kennypu Avatar answered Mar 16 '23 12:03

kennypu