angular-redux / store

Angular 2+ bindings for Redux
MIT License
1.34k stars 205 forks source link

Type issue with $select #541

Open dweedon opened 5 years ago

dweedon commented 5 years ago

This is a...

What toolchain are you using for transpilation/bundling?

Environment

NodeJS Version: 8 Typescript Version: 2.8 Angular Version: 6.0.3 @angular-redux/store version: ^9.0.0 OS: High Sierra

Expected Behaviour:

Given the following code:

const selector = (state: RootState): boolean => state.users.isSaving 
export class Users {
   ...

  @select$(
    selector,
    isSaving$ => isSaving$.pipe(map(isSaving => isSaving ? 'Saving…' : 'Save')),
  )
  saveButtonText$: Observable<string>;

saveButtonText$ should be an Observable<string>

Actual Behaviour:

It errors out when map(isSaving => isSaving ? 'Saving…' : 'Save') maps from Observable<boolean> to Observable<string>.

Additional Notes:

https://github.com/angular-redux/store/blob/master/src/decorators/select.ts#L62

off hand this should be something like

export function select$<T, A>(
  selector: Selector<any, T>,
  transformer: Transformer<T, A>,
  comparator?: Comparator
): PropertyDecorator {
  return decorate(selector, transformer, comparator);
}
cholt0425 commented 5 years ago

I agree. I am fighting with this issue right now. One of the most common things to do to data is to transform it into another object that is more suitable to be used by the UI but the object you select out of the state has to be the same type as what you transform it to, when you use select$