13
好吧,這是我的第一天使用打字機做一些Angular 2,我嘗試做一個簡單的getter和setter服務。Typescript 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;
}
}
任何人都可以解釋爲什麼打字稿編譯器拋出下面的錯誤,因爲我認爲它應該沒問題。
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).
如果有任何其他人絆倒因此您需要將類型定義爲數組,然後在<>中創建一個類,該類是描述數組項的結構的模型。 –