本文介绍了角度:“意外令牌.构造函数,方法,访问器或属性是预期的.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道为什么用var
或let
关键字声明变量时为什么会出现此编译错误?我的意思是,这很好:
I wonder why I get this compile error if I declare variable with var
or let
keywords? I mean, this goes well:
export class AppComponent {
refreshClickStream$: any;
constructor(){
}
这会带来错误:
export class AppComponent {
var refreshClickStream$: any;
constructor(){
}
推荐答案
在类中,TypeScript不允许使用
Inside a class, TypeScript doesn't permit the declaration of class members with
-
var
-
let
-
const
(您可以在媒体资源上使用readonly
)
var
let
const
(you can usereadonly
on the property)
此外,在类 ALSO 中,您将被禁止使用
Further, inside of a class ALSO you'll be prohibited from declarating functions with
-
function
所以你想要这个.
export class AppComponent {
a: string = "foo";
b: string = "bar";
foo(): void { }
constructor(){
}
}
不是
export class AppComponent {
var a: string = "foo";
let b: string = "bar";
function foo(): void { }
constructor(){
}
}
这篇关于角度:“意外令牌.构造函数,方法,访问器或属性是预期的.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!