dardo
dardo

Reputation: 4960

ngrx/store select does not exist

I'm trying to recreate the ngrx/store sample project a bit with the following code, I know this is quite a bit of overkill for a TODO app, but wanted to get the concepts down:

// 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());
  }

}

This code is creating two compile-time errors:

Property 'select' does not exist on type 'Observable<TodoState>'.
Property 'select' does not exist on type 'Observable<AppState>'.

I've tried a bunch of different variations on the Observable import, but that doesn't seem to matter, so I just took what the example app had:

import {Observable} from 'rxjs/Observable';

Any help would be greatly appreciated!

Upvotes: 3

Views: 1772

Answers (1)

menix
menix

Reputation: 168

It looks like you didn't import select and let, try adding the following imports:

import '@ngrx/core/add/operator/select';
import 'rxjs/add/operator/let'; 

Upvotes: 5

Related Questions