TypeScript не видит symbol-свойства

... при этом Symbol прекрасно работает с интерфейсами.

const symbol_property = Symbol()

type SomeType = { prop: number }

interface SomeInterface {
  normal_property: SomeType | null
  [symbol_property]: SomeType | null
}

class Some implements SomeInterface {

  normal_property: SomeType | null = null;
  [symbol_property]: SomeType | null = null;

  normal():number | null {
    if (!this.normal_property) return null
    return this.normal_property.prop++
  }

  symbol(): number | null {
    if (!this[symbol_property]) return null
    return this[symbol_property].prop++
    // error -> Object is possibly 'null'
  }

  fun(): number | null {
    const sp = this[symbol_property]
    if (!sp) return null
    return sp.prop++
  }

}

Playground

Это вообще возможно как-то исправить?
TypeScript - 4.4.0-dev.20210601


Ответы (0 шт):