[Feedback]Tons of errors in Angular 12 app
See original GitHub issuePage: /start/getting-started/data-model/q/integration/angular
Feedback:
Here are the following errors I am seeing initially, I attempted to fix some.
- Need to move the code from onInit into the constructor.
- Rrename file, ‘aws-exports.js’ to ‘aws-exports.ts’
- Assign empty array to class field
restaurants: Array<Restaurant> = [];
Error: src/app/app.component.ts:13:10 - error TS2564: Property 'createForm' has no initializer and is not definitely assigned in the constructor.
13 public createForm: FormGroup;
~~~~~~~~~~
Error: src/app/app.component.ts:15:3 - error TS2564: Property 'restaurants' has no initializer and is not definitely assigned in the constructor.
15 restaurants: Array<Restaurant>;
~~~~~~~~~~~
Error: src/app/app.component.ts:16:3 - error TS7008: Member 'subscription' implicitly has an 'any' type.
16 subscription;
~~~~~~~~~~~~
Error: src/app/app.component.ts:29:7 - error TS2322: Type '({ __typename: "Restaurant"; id: string; name: string; description: string; city: string; createdAt: string; updatedAt: string; } | null)[] | null | undefined' is not assignable to type 'Restaurant[]'.
Type 'undefined' is not assignable to type 'Restaurant[]'.
29 this.restaurants = event.items;
~~~~~~~~~~~~~~~~
Error: src/main.ts:5:25 - error TS7016: Could not find a declaration file for module './aws-exports'. '/home/yadav/dev/tmp/amplify-app/src/aws-exports.js' implicitly has an 'any' type.
5 import aws_exports from "./aws-exports";
~~~~~~~~~~~~~~~
After making these changes, there is still one more error I am unable to fix at the moment.
Error: src/app/app.component.ts:26:7 - error TS2322: Type '({ __typename: "Restaurant"; id: string; name: string; description: string; city: string; createdAt: string; updatedAt: string; } | null)[]' is not assignable to type 'Restaurant[]'.
Type '{ __typename: "Restaurant"; id: string; name: string; description: string; city: string; createdAt: string; updatedAt: string; } | null' is not assignable to type 'Restaurant'.
Type 'null' is not assignable to type 'Restaurant'.
26 this.restaurants = event.items;
~~~~~~~~~~~~~~~~
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Angular Error Handling Best Practices - Medium
Learn about centralizing Angular error handling by implementing a global error handler, client and server errors, writing good error messages and more.
Read more >Identify and Fix Build and Deployment Errors in Your Angular ...
In this guide, you will learn how to spot some of the most common build and deployment errors and how to resolve them...
Read more >Typescripts Errors on Angular 12 with Material 12
I created a new angular 12 project and run it with angular material - no errors occured. Did u try to delete node_modules...
Read more >ErrorHandler - Angular
The default implementation of ErrorHandler prints error messages to the console . To intercept error handling, write a custom exception handler that replaces ......
Read more >Error Handling with Angular 8 - Tips and Best Practices - Rollbar
Handling errors properly is essential in building a robust application in Angular. Error handlers provide an opportunity to present friendly ...
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
Hi @rajinder-yadav, thanks for your detailed feedback! These issues are stemming from Angular 12 enforcing Typescript strict mode by default. I opened up #3606 to provide the necessary updates to the documentation, based on your suggestions (also confirmed locally 🎉 ).
Here is the final fix in file
app.components.ts
, a typecast is required.Please update the doc and have someone go through everything for Angular 12, the text is out of date and it’s really frustrating to learn like this.