我是新手,在我的项目中学习 Typescript 和并行实现。我有一类用打字稿写的如下:
class Base {
property1!: number
property2!: string
getValue(field: string) {
const exists = Object.prototype.hasOwnProperty.call(this, field)
const value = this[field]
const isNotFunction = value !== 'function'
return exists && isNotFunction && field !== 'id' && field !== 'type'
}
}
现在tsc
命令给出了以下错误,这对我来说不太容易理解。请帮忙。
src/models/base.ts - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Base'.
No index signature with a parameter of type 'string' was found on type 'Base'.
137 const value = this[field]