How do i have to initialize an Object to avoid the error “Property ‘profile’ does not exist on type ‘Object’.”
At the moment i got:
.ts
user: Object;
.html:
{{user.profile}}
How do i have to initialize an Object to avoid the error “Property ‘profile’ does not exist on type ‘Object’.”
At the moment i got:
.ts
user: Object;
.html:
{{user.profile}}
public user: YourUserInterface = <any>{}; // hack for avoid typescript errors
{{user && user.profile}}
or
<div *ngIf="user">{{user.profile}}</div>
public ngOnInit(): Promise<any> {
return this.loading.create('SIGN_IN.LOADING.GET_USER, 'getUser') // it's my own service, you need to use LoadingController
.then(() => this.yourAPI.getUser())
.then(data => this.user = data)
.catch(error => this.notify.fail('calculator', error.message)) // it' my own service for show errors, you need to use yourself
.then(() => this.loading.dismiss('getUser')); // analog of finally section for promises. Fires both on success and error response
}
Thanks for your reply.
Ok. So i guess the nicest way is to do the check in the html? Thanks for that.
The error must be new right? Didn’t had that in ionic 2 beta?
I prefer initializing the user
with some dummy value in the constructor over cluttering up the template with checks. I would also define an actual interface that accurately describes the possible properties that a user can have instead of relying on the any
crutch if at all possible, so you can take advantage of TypeScript’s compile-time checking to catch dumb typos.
You mean something like this:
user: Object;
constructor(){
this.user = {icon: “”, title: “”}
}
Because this does not work?
Can i somehow “ignore” this errors because in the browser with ionic serve it works but when i do ionic build ios it drops the errors.
[22:50:11] ionic-app-scripts 0.0.45
[22:50:11] build prod started …
[22:50:11] clean started …
[22:50:11] clean finished in 5 ms
[22:50:11] copy started …
[22:50:11] ngc started …
[22:50:11] copy finished in 108 ms
[22:50:22] Error: Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/create-event/create-event.ngfactory.ts:1306:58
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/create-event/create-event.ngfactory.ts:1565:83
[22:50:22] Property ‘icon’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/create-event/create-event.ngfactory.ts:1570:84
[22:50:22] Property ‘title’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/create-event/create-event.ngfactory.ts:1845:60
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/create-event/create-event.ngfactory.ts:1905:29
[22:50:22] Supplied parameters do not match any signature of call target.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/list-events/list-events.ngfactory.ts:473:29
[22:50:22] Supplied parameters do not match any signature of call target.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:689:46
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:689:75
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:698:48
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:698:77
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:698:103
[22:50:22] Property ‘status’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:698:151
[22:50:22] Property ‘status’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:701:48
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:701:77
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:701:103
[22:50:22] Property ‘status’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:704:47
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:704:76
[22:50:22] Property ‘id’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:710:46
[22:50:22] Property ‘birthdate’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:713:46
[22:50:22] Property ‘quote’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:720:46
[22:50:22] Property ‘interests’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:723:46
[22:50:22] Property ‘city’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:757:79
[22:50:22] Property ‘firstname’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:757:111
[22:50:22] Property ‘lastname’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/profile/profile.ngfactory.ts:762:71
[22:50:22] Property ‘friends’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-chat/show-chat.ngfactory.ts:539:65
[22:50:22] Property ‘icon’ does not exist on type ‘ShowChatPage’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-chat/show-chat.ngfactory.ts:544:66
[22:50:22] Property ‘title’ does not exist on type ‘ShowChatPage’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-chat/show-chat.ngfactory.ts:584:42
[22:50:22] Property ‘goToMain’ does not exist on type ‘ShowChatPage’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:564:107
[22:50:22] Property ‘creator’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:564:144
[22:50:22] Property ‘profile’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:567:47
[22:50:22] Property ‘image’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:570:52
[22:50:22] Property ‘image’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:595:87
[22:50:22] Property ‘icon’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:600:82
[22:50:22] Property ‘date’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:605:82
[22:50:22] Property ‘time’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:610:82
[22:50:22] Property ‘location’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:615:78
[22:50:22] Property ‘description’ does not exist on type ‘Object’.
[22:50:22] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/show-event/show-event.ngfactory.ts:633:73
[22:50:22] Property ‘creator’ does not exist on type ‘Object’.
[22:50:22] ngc failed
[22:50:22] ionic-app-script task: “build”
[22:50:22] Error: Error
No, I suggested to stop using Object and instead actually doing something like:
export interface User {
id: string;
title: string;
icon?: string;
// other possible properties
}
I use an api.ts
at the root of the application to define these business-logic interfaces. You can put it wherever feels comfortable to you. I would not recommend putting it in the same file as the component, though, because you’ll probably also want to be referencing it in services.
Ok thanks for that, i will try that.
And what does this say? i found that it occurs because of the http request params, but i have no http request in the create-event.ts i just use the function dataService.post(); and in this function i have an http.post with all the parameters (url, data, options )?
Your suggestion with the export interface works fine. Thank you.
Now just these errors remain:
[23:45:11] Error: Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/create-event/create-event.ngfactory.ts:1905:29
[23:45:11] Supplied parameters do not match any signature of call target.
[23:45:11] Error at /Users/ddiesenreither/Development/TimeOut/Version
2/TimeOut/.tmp/pages/list-events/list-events.ngfactory.ts:473:29
[23:45:11] Supplied parameters do not match any signature of call target.
[23:45:11] ngc failed
[23:45:11] ionic-app-script task: “build”
[23:45:11] Error: Error
Anyone know how to fix them?
Fixed it:
In the list-chat.html i had a function createEvent(event) but in the list-chat.ts the function createEvent() withouth the parameter.