store icon indicating copy to clipboard operation
store copied to clipboard

Type issue with $select

Open dweedon opened this issue 6 years ago • 1 comments

This is a...

  • [ ] feature request
  • [x] bug report
  • [ ] usage question

What toolchain are you using for transpilation/bundling?

  • [x] @angular/cli
  • [ ] Custom @ngTools/webpack
  • [ ] Raw ngc
  • [ ] SystemJS
  • [ ] Rollup
  • [ ] Other

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

dweedon avatar Sep 04 '18 18:09 dweedon

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$

cholt0425 avatar Sep 18 '18 12:09 cholt0425