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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
=== tests/cases/conformance/classes/propertyMemberDeclarations/derivedUninitializedPropertyDeclaration.ts ===
class A {
>A : A
property = 'x';
>property : string
>'x' : "x"
m() { return 1 }
>m : () => number
>1 : 1
}
class B extends A {
>B : B
>A : A
property: any; // error
>property : any
}
class BD extends A {
>BD : BD
>A : A
declare property: any; // ok because it's implicitly initialised
>property : any
}
class BDBang extends A {
>BDBang : BDBang
>A : A
declare property!: any; // ! is not allowed, this is an ambient declaration
>property : any
}
class BOther extends A {
>BOther : BOther
>A : A
declare m() { return 2 } // not allowed on methods
>m : () => number
>2 : 2
declare nonce: any; // ok, even though it's not in the base
>nonce : any
declare property = 'y' // initialiser not allowed with declare
>property : string
>'y' : "y"
}
class U {
>U : U
declare nonce: any; // ok, even though there's no base
>nonce : any
}
class C {
>C : C
p: string;
>p : string
}
class D extends C {
>D : D
>C : C
p: 'hi'; // error
>p : "hi"
}
class DD extends C {
>DD : DD
>C : C
declare p: 'bye'; // ok
>p : "bye"
}
declare class E {
>E : E
p1: string
>p1 : string
p2: string
>p2 : string
}
class F extends E {
>F : F
>E : E
p1!: 'z'
>p1 : "z"
declare p2: 'alpha'
>p2 : "alpha"
}
class G extends E {
>G : G
>E : E
p1: 'z'
>p1 : "z"
constructor() {
super()
>super() : void
>super : typeof E
this.p1 = 'z'
>this.p1 = 'z' : "z"
>this.p1 : "z"
>this : this
>p1 : "z"
>'z' : "z"
}
}
abstract class H extends E {
>H : H
>E : E
abstract p1: 'a' | 'b' | 'c'
>p1 : "a" | "b" | "c"
declare abstract p2: 'a' | 'b' | 'c'
>p2 : "a" | "b" | "c"
}
interface I {
q: number
>q : number
}
interface J extends I { }
class J {
>J : J
r = 5
>r : number
>5 : 5
}
class K extends J {
>K : K
>J : J
q!: 1 | 2 | 3 // ok, extends a property from an interface
>q : 1 | 2 | 3
r!: 4 | 5 // error, from class
>r : 5 | 4
}
// #35327
class L {
>L : L
a: any;
>a : any
constructor(arg: any) {
>arg : any
this.a = arg;
>this.a = arg : any
>this.a : any
>this : this
>a : any
>arg : any
}
}
class M extends L {
>M : M
>L : L
declare a: number;
>a : number
constructor(arg: number) {
>arg : number
super(arg);
>super(arg) : void
>super : typeof L
>arg : number
console.log(this.a); // should be OK, M.a is ambient
>console.log(this.a) : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>this.a : number
>this : this
>a : number
}
}
|