user10196907
user10196907

Reputation:

How to ignore typescript or idm errors?

I have an angular project, In the project, I have a service it returns an object, And In the app component, I'm using that object.

theobject.profileImg

Everything works properly, But Idm shows this err. " Property 'profileImg' does not exist on type 'object'. "

I'm using vsCode

enter image description here

Upvotes: 0

Views: 56

Answers (3)

qiAlex
qiAlex

Reputation: 4346

Generally it is always better to prepare types properly and avoid situations like you have.

for example:

export interface SomeInterface{
  public profileImg: any;
}

const anotherVar: SomeInterface = theobject;
anotherVar.profileImg; // this will be fine

Another option is use any type:

(company as any).profileImg

Or

theobject['profileImg']

Also, if you just want to skip it in one place use @ts-ignore

// @ts-ignore: some description
theobject.profileImg

Or disable linting at all.

Upvotes: 0

Random
Random

Reputation: 3236

using type Object shows this kind of error. The best practice is to create your own interface (which will have the attribute profileImg) to enable autocompletion. If you choose not to do so, use type any instead

Upvotes: 1

qwerty
qwerty

Reputation: 699

In template use like:

theobject?.profileImg

or

theobject['profileImg']

but generally better add model to your object, like:

theobject: IObject;

and

interface IObject {
 profileImg: string;
 id: number;
 //and more
}

Upvotes: 1

Related Questions