valueChanges() loses type information
See original GitHub issueUsing Angularfire2@5.0.0-rc.3.
Calling .valueChanges()
on an AngularFireObject<T>
should return an Observable<T | null>
, but instead returns Observable<{} | null>
.
Similarly, calling .valueChanges()
on an AngularFireList<T>
should return an Observable<T[]>
, but instead returns Observable<{}[]>
.
This results in error messages for code that should be correct. For example, the following code:
interface FooBar {
foo: string;
bar: number;
}
afDb.object<FooBar>("/foo-bar/1")
.valueChanges()
.subscribe(fooBarItem => {
if (fooBarItem !== null) {
console.log(`Foo: ${fooBarItem.foo}, Bar:${fooBarItem.bar}`);
}
});
afDb.list<FooBar>("/foo-bar")
.valueChanges()
.subscribe(fooBarArray => {
fooBarArray.forEach(fooBarItem => {
console.log(`Foo: ${fooBarItem.foo}, Bar:${fooBarItem.bar}`);
});
});
yields the following TypeScript errors on the console.log()
statements:
Property 'foo' does not exist on type '{}'.
Property 'bar' does not exist on type '{}'.
Property 'foo' does not exist on type '{}'.
Property 'bar' does not exist on type '{}'.
I think fixing this problem is simply a matter of setting the return type explicitly for the .valueChanges()
function.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top Results From Across the Web
valueChanges() loses type information · Issue #1299 - GitHub
I think fixing this problem is simply a matter of setting the return type explicitly for the .valueChanges() function.
Read more >Reactive Form valueChanges observable resets form value
The problem was that the form.value[field] was referenced by the item.dataList, instead of being managed separately. Share.
Read more >Angular Reactive Forms: Tips and Tricks | by Netanel Basal
Whenever we call a control's disable() or enable() methods, Angular triggers the valueChanges event. Yes, it may surprise you because the “value” didn't ......
Read more >5 tips on using Angular FormControl | by Alain Chautard
5. Subscribing to form updates using the valueChanges and statusChanges observables · valueChanges — Emits all value updates as soon as they ...
Read more >How to do Conditional Validation on valueChanges method in ...
In Reactive forms both FormControls and FormGroups has a valueChanges method. It returns an observable type, so you can subscribe to it, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
i think a more elegant workaround until this gets fixed would be to explicitly cast the output of
.valueChanges()
to your desired typeDespite creating a complete interface that reflected my database… I had to add
[propName: string]: any;
to my interface to get it to stop complaining… pretty ugly stuff.