ngxtension/ngxtension-platform

`derivedFrom`: cannot provide `undefined` as `initialValue`

Opened this issue · 2 comments

I noticed that an initial value of undefined cannot be used in derivedFrom. I think this would be okay in itself because Angular is using undefined implicitly as initial value. But derivedFrom is setting requireSync: true when it detects no initial value, cf.


and that does not work with async observables as sources

The problem seems to be here:

const hasInitValue = options?.initialValue !== undefined;

derivedFrom is checking options?.initialValue !== undefined;, thus an initial value of undefined gets lost.

I guess this could be fixed by using Object.hasOwn(options, 'initialValue') instead?

@mattmoos Can you provide a PR that adds a test case with your usecase (simplified) that breaks, and we can work on a fix or just use what you recommended (object.hasOwn).

Yes, just had a look at the existing test cases. I think I can provide a test.