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
|
=== tests/cases/compiler/gettersAndSetters.ts ===
// classes
class C {
>C : C
public fooBack = "";
>fooBack : string
>"" : ""
static barBack:string = "";
>barBack : string
>"" : ""
public bazBack = "";
>bazBack : string
>"" : ""
public get Foo() { return this.fooBack;} // ok
>Foo : string
>this.fooBack : string
>this : this
>fooBack : string
public set Foo(foo:string) {this.fooBack = foo;} // ok
>Foo : string
>foo : string
>this.fooBack = foo : string
>this.fooBack : string
>this : this
>fooBack : string
>foo : string
static get Bar() {return C.barBack;} // ok
>Bar : string
>C.barBack : string
>C : typeof C
>barBack : string
static set Bar(bar:string) {C.barBack = bar;} // ok
>Bar : string
>bar : string
>C.barBack = bar : string
>C.barBack : string
>C : typeof C
>barBack : string
>bar : string
public get = function() {} // ok
>get : () => void
>function() {} : () => void
public set = function() {} // ok
>set : () => void
>function() {} : () => void
}
var c = new C();
>c : C
>new C() : C
>C : typeof C
var foo = c.Foo;
>foo : string
>c.Foo : string
>c : C
>Foo : string
c.Foo = "foov";
>c.Foo = "foov" : "foov"
>c.Foo : string
>c : C
>Foo : string
>"foov" : "foov"
var bar = C.Bar;
>bar : string
>C.Bar : string
>C : typeof C
>Bar : string
C.Bar = "barv";
>C.Bar = "barv" : "barv"
>C.Bar : string
>C : typeof C
>Bar : string
>"barv" : "barv"
var baz = c.Baz;
>baz : any
>c.Baz : any
>c : C
>Baz : any
c.Baz = "bazv";
>c.Baz = "bazv" : "bazv"
>c.Baz : any
>c : C
>Baz : any
>"bazv" : "bazv"
// The Foo accessors' return and param types should be contextually typed to the Foo field
var o : {Foo:number;} = {get Foo() {return 0;}, set Foo(val:number){val}}; // o
>o : { Foo: number; }
>Foo : number
>{get Foo() {return 0;}, set Foo(val:number){val}} : { Foo: number; }
>Foo : number
>0 : 0
>Foo : number
>val : number
>val : number
var ofg = o.Foo;
>ofg : number
>o.Foo : number
>o : { Foo: number; }
>Foo : number
o.Foo = 0;
>o.Foo = 0 : 0
>o.Foo : number
>o : { Foo: number; }
>Foo : number
>0 : 0
interface I1 {
(n:number):number;
>n : number
}
var i:I1 = function (n) {return n;}
>i : I1
>function (n) {return n;} : (n: number) => number
>n : number
>n : number
// Repro from #45006
const x: string | number = Math.random() < 0.5 ? "str" : 123;
>x : string | number
>Math.random() < 0.5 ? "str" : 123 : "str" | 123
>Math.random() < 0.5 : boolean
>Math.random() : number
>Math.random : () => number
>Math : Math
>random : () => number
>0.5 : 0.5
>"str" : "str"
>123 : 123
if (typeof x === "string") {
>typeof x === "string" : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : string | number
>"string" : "string"
let obj = {
>obj : { prop: any; method(): string; }
>{ set prop(_: any) { x.toUpperCase(); }, get prop() { return x.toUpperCase() }, method() { return x.toUpperCase() } } : { prop: any; method(): string; }
set prop(_: any) { x.toUpperCase(); },
>prop : any
>_ : any
>x.toUpperCase() : string
>x.toUpperCase : () => string
>x : string
>toUpperCase : () => string
get prop() { return x.toUpperCase() },
>prop : any
>x.toUpperCase() : string
>x.toUpperCase : () => string
>x : string
>toUpperCase : () => string
method() { return x.toUpperCase() }
>method : () => string
>x.toUpperCase() : string
>x.toUpperCase : () => string
>x : string
>toUpperCase : () => string
}
}
|