Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngOnInit(): void breaks shipping.component.ts #55066

Closed
goodwinchris opened this issue Mar 27, 2024 · 3 comments
Closed

ngOnInit(): void breaks shipping.component.ts #55066

goodwinchris opened this issue Mar 27, 2024 · 3 comments

Comments

@goodwinchris
Copy link

goodwinchris commented Mar 27, 2024

Describe the problem that you experienced

When following along with the getting started tutorial, I'm prevented from moving forward with the following error:

Type 'void' is not assignable to type 'Observable<{ type: string; price: number; }[]>'.

Enter the URL of the topic with the problem

https://angular.io/start/start-data#configuring-the-shippingcomponent-to-use-cartservice

Describe what you were looking for in the documentation

No response

Describe the actions that led you to experience the problem

Just following along with the tutorial.

Describe what you want to experience that would fix the problem

I'd like a change to the code which resolves the issue or an explanation about how I can resolve it myself.

Add a screenshot if that helps illustrate the problem

Screenshot 2024-03-27 at 11 06 10 AM Screenshot 2024-03-27 at 11 06 15 AM

If this problem caused an exception or error, please paste it here

Type 'void' is not assignable to type 'Observable<{ type: string; price: number; }[]>'.(2322)
(property) ShippingComponent.shippingCosts: Observable<{
    type: string;
    price: number;
}[]>


### If the problem is browser-specific, please specify the device, OS, browser, and version

_No response_

### Provide any additional information here in as much as detail as you can

_No response_
@goodwinchris goodwinchris changed the title ngOnInit: void breaks shipping.component.ts ngOnInit(): void breaks shipping.component.ts Mar 27, 2024
@alxhub
Copy link
Member

alxhub commented Mar 27, 2024

The code in the tutorial is correct. TypeScript is correctly telling you that in your code, this.cartService.getShippingPrices() is returning void which is not assignable to the Observable. It has nothing to do with ngOnInit or its return type - you likely did not return anything from getShippingPrices().

@alxhub alxhub closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
@goodwinchris
Copy link
Author

You are correct, it appears I missed the return in getShippingPrices(). Thank you for the reply.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants