好的,这是我第一天使用typescript做一些Angular 2,我正在尝试做一个简单的getter和setter服务。
import {Injectable} from "angular2/core";
@Injectable()
export class TodoService {
private _todos:Array = [];
get todos():Array {
return this._todos;
}
set todos(value:Array) {
this._todos = value;
}
}谁能解释为什么Typescript编译器抛出下面的错误,因为我认为它应该是好的。
ERROR in [default] /Users/testguy/WebstormProjects/angular2-seed/src/app/services/todo-service.ts:6:17
Generic type 'Array<T>' requires 1 type argument(s).
ERROR in [default] /Users/testguy/WebstormProjects/angular2-seed/src/app/services/todo-service.ts:8:14
Generic type 'Array<T>' requires 1 type argument(s).
ERROR in [default] /Users/testguy/WebstormProjects/angular2-seed/src/app/services/todo-service.ts:12:18
Generic type 'Array<T>' requires 1 type argument(s).发布于 2016-04-16 21:41:03
您确实需要在定义它时说明您想要哪种类型的数据类型,MyClass可以是string/number(数据类型)。
代码
export class TodoService {
private _todos:Array<MyClass> = [];
get todos():Array<MyClass> {
return this._todos;
}
set todos(value:Array<MyClass>) {
this._todos = value;
}
}https://stackoverflow.com/questions/36664824
复制相似问题