M
M
mrSeller2021-05-13 19:45:22
typescript
mrSeller, 2021-05-13 19:45:22

How to resolve error TS2339: Property 'xxx' does not exist on type 'yyy'?

There is a class:

export default class BaseModel {
  _: {} = {}

  constructor (options: OptionsInterface) {
    const { model, aliases } = options

    Object.keys(aliases).forEach(key => {
      const alias = aliases[key]
      this._[alias] = model[key]
    })
  }
}


And every mention of the _ property of this class gives the following error:
TS2339: Property '_' does not exist on type 'BaseModel'

I restart the assembly, the error disappears, I make a change - the error gets out.

I explicitly declare a property, I give it a type and a default value, but what does it give me that this property is not in the class?
And why can't I assign a lowercase type object(error: ESLint: 'object' is not defined.(no-undef))?
I'm going bald soon, cuckoo rides from this typescript

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2021-05-18
@bingo347

https://www.typescriptlang.org/play?#code/C4TwDgpg...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question