class
类的get和set
ts在编译get和set的时候默认是es3编译,vscode编辑器会报错error TS1056: Accessors are only available when targeting ECMAScript 5 and higher
需要编译到版本ES5或以上,解决办法:$ tsc xxx.ts -t es5
。
class User{ myname:string; constructor(myname:string){ this.myname = myname } get name(){ return this.myname } set name(newName:string){ this.myname = newName } }
interface