我正在尝试使用以下代码重新创建 ngrx/store 示例项目,我知道这对于 TODO 应用程序来说有点矫枉过正,但我想把这些概念记下来:
// State Model
interface Todo {
id: number;
text: string;
completed: boolean;
}
interface TodoState {
entities: Todo[];
}
interface AppState {
todos: TodoState;
}
// State Retrieval
getTodos() {
return (state: Observable<TodoState>) => state.select(s => s.entities);
}
getTodoState() {
return (state: Observable<AppState>) => state.select(s => s.todos);
}
getTodosCollection() {
return compose(this.getTodos(), this.getTodoState());
}
@Component({...})
class App {
// I'd think I should be able to type this to Array<Todo>,
// but that throws a compile-time error.
// Also, I'm assuming the $ is convention to designate
// a stream.
todos$: Observable<any>;
constructor(private store:Store<AppState>) {
this.todos = store.let(this.getTodosCollection());
}
}
此代码正在创建两个编译时错误:
Property 'select' does not exist on type 'Observable<TodoState>'.
Property 'select' does not exist on type 'Observable<AppState>'.
我在 Observable 导入上尝试了许多不同的变体,但这似乎并不重要,所以我只是采用了示例应用程序的内容:
import {Observable} from 'rxjs/Observable';
任何帮助将不胜感激!