Angularfire: Spread types may only be created from object types

Created on 16 May 2018  路  3Comments  路  Source: angular/angularfire

I am not sure if this is a bug, but after upgrading to [email protected] I get this strange error on our spread operators. I created a small stackblitz that illustrates how we use the snapshotChanges() in our project. If you install [email protected] there are no errors.

Version info

Angular: 6

Firebase: 5.0.2

AngularFire: 5.0.0-rc.9

How to reproduce these conditions

https://stackblitz.com/edit/spread-operator-error

Open stackblitz

Debug output

screen shot 2018-05-16 at 21 17 11

Expected behavior


No error

Actual behavior


Typescript gives error

ERROR in <path-to-file>: error TS2698: Spread types may only be created from object types.

Most helpful comment

This was a breaking change in RC 9, we fixed the typings :P

Your data object is now a Shirt. Odd that it's not spreading for you, you might want to look at your Shirt interface... I'll play around with this in my test project.

In the meantime you could do ...(data as {})

All 3 comments

This was a breaking change in RC 9, we fixed the typings :P

Your data object is now a Shirt. Odd that it's not spreading for you, you might want to look at your Shirt interface... I'll play around with this in my test project.

In the meantime you could do ...(data as {})

Thanks for the quick response.

Am also playing around, and the suggeste fix work.

I think it boils down to my (limited) understanding of functions that handle types dynamically. Like the queryCollection function should probably have a return signature, of a different type than, say, Observable

But thanks anyway!

Ah, so yeah you're losing the type information when you pass the reference + the default is any

I forked your StackBlitz and altered it to achieve what I think you're looking for https://stackblitz.com/edit/spread-operator-error-j5r6nm?file=src/app/app.component.ts

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StephenFluin picture StephenFluin  路  3Comments

mypark picture mypark  路  3Comments

aucevica picture aucevica  路  3Comments

avanderbergh picture avanderbergh  路  3Comments

jnupeter picture jnupeter  路  3Comments