File size: 1,161 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react'

interface Animal {
  animalStuff: any
}
interface Dog extends Animal {
  dogStuff: any
}

class AnimalHouse {
  resident: Animal
  constructor(animal: Animal) {
    this.resident = animal
  }
}
class DogHouse extends AnimalHouse {
  // Initializes 'resident' to 'undefined'
  // after the call to 'super()' when
  // using 'useDefineForClassFields'!
  // @ts-ignore
  resident: Dog
  // useless constructor only for type checker
  /* eslint-disable @typescript-eslint/no-useless-constructor */
  constructor(dog: Dog) {
    super(dog)
  }
}

class DogHouseWithDeclare extends AnimalHouse {
  declare resident: Dog
  // useless constructor only for type checker
  /* eslint-disable @typescript-eslint/no-useless-constructor */
  constructor(dog: Dog) {
    super(dog)
  }
}

export default function AnimalView() {
  const dog = new DogHouse({
    animalStuff: 'animal',
    dogStuff: 'dog',
  })
  const dogDeclare = new DogHouseWithDeclare({
    animalStuff: 'animal',
    dogStuff: 'dog',
  })
  return (
    <>
      <div id={'dog'}>{dog.resident}</div>
      <div id={'dogDecl'}>{dogDeclare.resident?.dogStuff}</div>
    </>
  )
}