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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
|
=== tests/cases/conformance/expressions/typeAssertions/constAssertions.ts ===
let v1 = 'abc' as const;
>v1 : Symbol(v1, Decl(constAssertions.ts, 0, 3))
>const : Symbol(const)
let v2 = `abc` as const;
>v2 : Symbol(v2, Decl(constAssertions.ts, 1, 3))
>const : Symbol(const)
let v3 = 10 as const;
>v3 : Symbol(v3, Decl(constAssertions.ts, 2, 3))
>const : Symbol(const)
let v4 = -10 as const;
>v4 : Symbol(v4, Decl(constAssertions.ts, 3, 3))
>const : Symbol(const)
let v5 = +10 as const;
>v5 : Symbol(v5, Decl(constAssertions.ts, 4, 3))
>const : Symbol(const)
let v6 = 10n as const;
>v6 : Symbol(v6, Decl(constAssertions.ts, 5, 3))
>const : Symbol(const)
let v7 = -10n as const;
>v7 : Symbol(v7, Decl(constAssertions.ts, 6, 3))
>const : Symbol(const)
let v8 = true as const;
>v8 : Symbol(v8, Decl(constAssertions.ts, 7, 3))
>const : Symbol(const)
let v9 = false as const;
>v9 : Symbol(v9, Decl(constAssertions.ts, 8, 3))
>const : Symbol(const)
let c1 = 'abc' as const;
>c1 : Symbol(c1, Decl(constAssertions.ts, 10, 3))
>const : Symbol(const)
let c2 = `abc` as const;
>c2 : Symbol(c2, Decl(constAssertions.ts, 11, 3))
>const : Symbol(const)
let c3 = 10 as const;
>c3 : Symbol(c3, Decl(constAssertions.ts, 12, 3))
>const : Symbol(const)
let c4 = -10 as const;
>c4 : Symbol(c4, Decl(constAssertions.ts, 13, 3))
>const : Symbol(const)
let c5 = +10 as const;
>c5 : Symbol(c5, Decl(constAssertions.ts, 14, 3))
>const : Symbol(const)
let c6 = 10n as const;
>c6 : Symbol(c6, Decl(constAssertions.ts, 15, 3))
>const : Symbol(const)
let c7 = -10n as const;
>c7 : Symbol(c7, Decl(constAssertions.ts, 16, 3))
>const : Symbol(const)
let c8 = true as const;
>c8 : Symbol(c8, Decl(constAssertions.ts, 17, 3))
>const : Symbol(const)
let c9 = false as const;
>c9 : Symbol(c9, Decl(constAssertions.ts, 18, 3))
>const : Symbol(const)
let vv1 = v1;
>vv1 : Symbol(vv1, Decl(constAssertions.ts, 20, 3))
>v1 : Symbol(v1, Decl(constAssertions.ts, 0, 3))
let vc1 = c1;
>vc1 : Symbol(vc1, Decl(constAssertions.ts, 21, 3))
>c1 : Symbol(c1, Decl(constAssertions.ts, 10, 3))
let a1 = [] as const;
>a1 : Symbol(a1, Decl(constAssertions.ts, 23, 3))
>const : Symbol(const)
let a2 = [1, 2, 3] as const;
>a2 : Symbol(a2, Decl(constAssertions.ts, 24, 3))
>const : Symbol(const)
let a3 = [10, 'hello', true] as const;
>a3 : Symbol(a3, Decl(constAssertions.ts, 25, 3))
>const : Symbol(const)
let a4 = [...[1, 2, 3]] as const;
>a4 : Symbol(a4, Decl(constAssertions.ts, 26, 3))
>const : Symbol(const)
let a5 = [1, 2, 3];
>a5 : Symbol(a5, Decl(constAssertions.ts, 27, 3))
let a6 = [...a5] as const;
>a6 : Symbol(a6, Decl(constAssertions.ts, 28, 3))
>a5 : Symbol(a5, Decl(constAssertions.ts, 27, 3))
>const : Symbol(const)
let a7 = [...a6];
>a7 : Symbol(a7, Decl(constAssertions.ts, 29, 3))
>a6 : Symbol(a6, Decl(constAssertions.ts, 28, 3))
let a8 = ['abc', ...a7] as const;
>a8 : Symbol(a8, Decl(constAssertions.ts, 30, 3))
>a7 : Symbol(a7, Decl(constAssertions.ts, 29, 3))
>const : Symbol(const)
let a9 = [...a8];
>a9 : Symbol(a9, Decl(constAssertions.ts, 31, 3))
>a8 : Symbol(a8, Decl(constAssertions.ts, 30, 3))
declare let d: { [x: string]: string };
>d : Symbol(d, Decl(constAssertions.ts, 33, 11))
>x : Symbol(x, Decl(constAssertions.ts, 33, 18))
let o1 = { x: 10, y: 20 } as const;
>o1 : Symbol(o1, Decl(constAssertions.ts, 35, 3))
>x : Symbol(x, Decl(constAssertions.ts, 35, 10))
>y : Symbol(y, Decl(constAssertions.ts, 35, 17))
>const : Symbol(const)
let o2 = { a: 1, 'b': 2, ['c']: 3, d() {}, ['e' + '']: 4 } as const;
>o2 : Symbol(o2, Decl(constAssertions.ts, 36, 3))
>a : Symbol(a, Decl(constAssertions.ts, 36, 10))
>'b' : Symbol('b', Decl(constAssertions.ts, 36, 16))
>['c'] : Symbol(['c'], Decl(constAssertions.ts, 36, 24))
>'c' : Symbol(['c'], Decl(constAssertions.ts, 36, 24))
>d : Symbol(d, Decl(constAssertions.ts, 36, 34))
>['e' + ''] : Symbol(['e' + ''], Decl(constAssertions.ts, 36, 42))
>const : Symbol(const)
let o3 = { ...o1, ...o2 } as const;
>o3 : Symbol(o3, Decl(constAssertions.ts, 37, 3))
>o1 : Symbol(o1, Decl(constAssertions.ts, 35, 3))
>o2 : Symbol(o2, Decl(constAssertions.ts, 36, 3))
>const : Symbol(const)
let o4 = { a: 1, b: 2 };
>o4 : Symbol(o4, Decl(constAssertions.ts, 38, 3))
>a : Symbol(a, Decl(constAssertions.ts, 38, 10))
>b : Symbol(b, Decl(constAssertions.ts, 38, 16))
let o5 = { ...o4 } as const;
>o5 : Symbol(o5, Decl(constAssertions.ts, 39, 3))
>o4 : Symbol(o4, Decl(constAssertions.ts, 38, 3))
>const : Symbol(const)
let o6 = { ...o5 };
>o6 : Symbol(o6, Decl(constAssertions.ts, 40, 3))
>o5 : Symbol(o5, Decl(constAssertions.ts, 39, 3))
let o7 = { ...d } as const;
>o7 : Symbol(o7, Decl(constAssertions.ts, 41, 3))
>d : Symbol(d, Decl(constAssertions.ts, 33, 11))
>const : Symbol(const)
let o8 = { ...o7 };
>o8 : Symbol(o8, Decl(constAssertions.ts, 42, 3))
>o7 : Symbol(o7, Decl(constAssertions.ts, 41, 3))
let o9 = { x: 10, foo() { this.x = 20 } } as const; // Error
>o9 : Symbol(o9, Decl(constAssertions.ts, 43, 3))
>x : Symbol(x, Decl(constAssertions.ts, 43, 10))
>foo : Symbol(foo, Decl(constAssertions.ts, 43, 17))
>this.x : Symbol(x, Decl(constAssertions.ts, 43, 10))
>this : Symbol(__object, Decl(constAssertions.ts, 43, 8))
>x : Symbol(x, Decl(constAssertions.ts, 43, 10))
>const : Symbol(const)
let p1 = (10) as const;
>p1 : Symbol(p1, Decl(constAssertions.ts, 45, 3))
>const : Symbol(const)
let p2 = ((-10)) as const;
>p2 : Symbol(p2, Decl(constAssertions.ts, 46, 3))
>const : Symbol(const)
let p3 = ([(10)]) as const;
>p3 : Symbol(p3, Decl(constAssertions.ts, 47, 3))
>const : Symbol(const)
let p4 = [[[[10]]]] as const;
>p4 : Symbol(p4, Decl(constAssertions.ts, 48, 3))
>const : Symbol(const)
let x1 = { x: 10, y: [20, 30], z: { a: { b: 42 } } } as const;
>x1 : Symbol(x1, Decl(constAssertions.ts, 50, 3))
>x : Symbol(x, Decl(constAssertions.ts, 50, 10))
>y : Symbol(y, Decl(constAssertions.ts, 50, 17))
>z : Symbol(z, Decl(constAssertions.ts, 50, 30))
>a : Symbol(a, Decl(constAssertions.ts, 50, 35))
>b : Symbol(b, Decl(constAssertions.ts, 50, 40))
>const : Symbol(const)
let q1 = <const> 10;
>q1 : Symbol(q1, Decl(constAssertions.ts, 52, 3))
>const : Symbol(const)
let q2 = <const> 'abc';
>q2 : Symbol(q2, Decl(constAssertions.ts, 53, 3))
>const : Symbol(const)
let q3 = <const> true;
>q3 : Symbol(q3, Decl(constAssertions.ts, 54, 3))
>const : Symbol(const)
let q4 = <const> [1, 2, 3];
>q4 : Symbol(q4, Decl(constAssertions.ts, 55, 3))
>const : Symbol(const)
let q5 = <const> { x: 10, y: 20 };
>q5 : Symbol(q5, Decl(constAssertions.ts, 56, 3))
>const : Symbol(const)
>x : Symbol(x, Decl(constAssertions.ts, 56, 18))
>y : Symbol(y, Decl(constAssertions.ts, 56, 25))
declare function id<T>(x: T): T;
>id : Symbol(id, Decl(constAssertions.ts, 56, 34))
>T : Symbol(T, Decl(constAssertions.ts, 58, 20))
>x : Symbol(x, Decl(constAssertions.ts, 58, 23))
>T : Symbol(T, Decl(constAssertions.ts, 58, 20))
>T : Symbol(T, Decl(constAssertions.ts, 58, 20))
let e1 = v1 as const; // Error
>e1 : Symbol(e1, Decl(constAssertions.ts, 60, 3))
>v1 : Symbol(v1, Decl(constAssertions.ts, 0, 3))
>const : Symbol(const)
let e2 = (true ? 1 : 0) as const; // Error
>e2 : Symbol(e2, Decl(constAssertions.ts, 61, 3))
>const : Symbol(const)
let e3 = id(1) as const; // Error
>e3 : Symbol(e3, Decl(constAssertions.ts, 62, 3))
>id : Symbol(id, Decl(constAssertions.ts, 56, 34))
>const : Symbol(const)
let t1 = 'foo' as const;
>t1 : Symbol(t1, Decl(constAssertions.ts, 64, 3))
>const : Symbol(const)
let t2 = 'bar' as const;
>t2 : Symbol(t2, Decl(constAssertions.ts, 65, 3))
>const : Symbol(const)
let t3 = `${t1}-${t2}` as const;
>t3 : Symbol(t3, Decl(constAssertions.ts, 66, 3))
>t1 : Symbol(t1, Decl(constAssertions.ts, 64, 3))
>t2 : Symbol(t2, Decl(constAssertions.ts, 65, 3))
>const : Symbol(const)
let t4 = `${`(${t1})`}-${`(${t2})`}` as const;
>t4 : Symbol(t4, Decl(constAssertions.ts, 67, 3))
>t1 : Symbol(t1, Decl(constAssertions.ts, 64, 3))
>t2 : Symbol(t2, Decl(constAssertions.ts, 65, 3))
>const : Symbol(const)
function ff1(x: 'foo' | 'bar', y: 1 | 2) {
>ff1 : Symbol(ff1, Decl(constAssertions.ts, 67, 46))
>x : Symbol(x, Decl(constAssertions.ts, 69, 13))
>y : Symbol(y, Decl(constAssertions.ts, 69, 30))
return `${x}-${y}` as const;
>x : Symbol(x, Decl(constAssertions.ts, 69, 13))
>y : Symbol(y, Decl(constAssertions.ts, 69, 30))
>const : Symbol(const)
}
function ff2<T extends string, U extends string>(x: T, y: U) {
>ff2 : Symbol(ff2, Decl(constAssertions.ts, 71, 1))
>T : Symbol(T, Decl(constAssertions.ts, 73, 13))
>U : Symbol(U, Decl(constAssertions.ts, 73, 30))
>x : Symbol(x, Decl(constAssertions.ts, 73, 49))
>T : Symbol(T, Decl(constAssertions.ts, 73, 13))
>y : Symbol(y, Decl(constAssertions.ts, 73, 54))
>U : Symbol(U, Decl(constAssertions.ts, 73, 30))
return `${x}-${y}` as const;
>x : Symbol(x, Decl(constAssertions.ts, 73, 49))
>y : Symbol(y, Decl(constAssertions.ts, 73, 54))
>const : Symbol(const)
}
const ts1 = ff2('foo', 'bar');
>ts1 : Symbol(ts1, Decl(constAssertions.ts, 77, 5))
>ff2 : Symbol(ff2, Decl(constAssertions.ts, 71, 1))
const ts2 = ff2('foo', !!true ? '0' : '1');
>ts2 : Symbol(ts2, Decl(constAssertions.ts, 78, 5))
>ff2 : Symbol(ff2, Decl(constAssertions.ts, 71, 1))
const ts3 = ff2(!!true ? 'top' : 'bottom', !!true ? 'left' : 'right');
>ts3 : Symbol(ts3, Decl(constAssertions.ts, 79, 5))
>ff2 : Symbol(ff2, Decl(constAssertions.ts, 71, 1))
function ff3(x: 'foo' | 'bar', y: object) {
>ff3 : Symbol(ff3, Decl(constAssertions.ts, 79, 70))
>x : Symbol(x, Decl(constAssertions.ts, 81, 13))
>y : Symbol(y, Decl(constAssertions.ts, 81, 30))
return `${x}${y}` as const;
>x : Symbol(x, Decl(constAssertions.ts, 81, 13))
>y : Symbol(y, Decl(constAssertions.ts, 81, 30))
>const : Symbol(const)
}
type Action = "verify" | "write";
>Action : Symbol(Action, Decl(constAssertions.ts, 83, 1))
type ContentMatch = "match" | "nonMatch";
>ContentMatch : Symbol(ContentMatch, Decl(constAssertions.ts, 85, 33))
type Outcome = `${Action}_${ContentMatch}`;
>Outcome : Symbol(Outcome, Decl(constAssertions.ts, 86, 41))
>Action : Symbol(Action, Decl(constAssertions.ts, 83, 1))
>ContentMatch : Symbol(ContentMatch, Decl(constAssertions.ts, 85, 33))
function ff4(verify: boolean, contentMatches: boolean) {
>ff4 : Symbol(ff4, Decl(constAssertions.ts, 87, 43))
>verify : Symbol(verify, Decl(constAssertions.ts, 89, 13))
>contentMatches : Symbol(contentMatches, Decl(constAssertions.ts, 89, 29))
const action : Action = verify ? `verify` : `write`;
>action : Symbol(action, Decl(constAssertions.ts, 90, 9))
>Action : Symbol(Action, Decl(constAssertions.ts, 83, 1))
>verify : Symbol(verify, Decl(constAssertions.ts, 89, 13))
const contentMatch: ContentMatch = contentMatches ? `match` : `nonMatch`;
>contentMatch : Symbol(contentMatch, Decl(constAssertions.ts, 91, 9))
>ContentMatch : Symbol(ContentMatch, Decl(constAssertions.ts, 85, 33))
>contentMatches : Symbol(contentMatches, Decl(constAssertions.ts, 89, 29))
const outcome: Outcome = `${action}_${contentMatch}` as const;
>outcome : Symbol(outcome, Decl(constAssertions.ts, 92, 9))
>Outcome : Symbol(Outcome, Decl(constAssertions.ts, 86, 41))
>action : Symbol(action, Decl(constAssertions.ts, 90, 9))
>contentMatch : Symbol(contentMatch, Decl(constAssertions.ts, 91, 9))
>const : Symbol(const)
return outcome;
>outcome : Symbol(outcome, Decl(constAssertions.ts, 92, 9))
}
function ff5(verify: boolean, contentMatches: boolean) {
>ff5 : Symbol(ff5, Decl(constAssertions.ts, 94, 1))
>verify : Symbol(verify, Decl(constAssertions.ts, 96, 13))
>contentMatches : Symbol(contentMatches, Decl(constAssertions.ts, 96, 29))
const action = verify ? `verify` : `write`;
>action : Symbol(action, Decl(constAssertions.ts, 97, 9))
>verify : Symbol(verify, Decl(constAssertions.ts, 96, 13))
const contentMatch = contentMatches ? `match` : `nonMatch`;
>contentMatch : Symbol(contentMatch, Decl(constAssertions.ts, 98, 9))
>contentMatches : Symbol(contentMatches, Decl(constAssertions.ts, 96, 29))
const outcome = `${action}_${contentMatch}` as const;
>outcome : Symbol(outcome, Decl(constAssertions.ts, 99, 9))
>action : Symbol(action, Decl(constAssertions.ts, 97, 9))
>contentMatch : Symbol(contentMatch, Decl(constAssertions.ts, 98, 9))
>const : Symbol(const)
return outcome;
>outcome : Symbol(outcome, Decl(constAssertions.ts, 99, 9))
}
function accessorNames<S extends string>(propName: S) {
>accessorNames : Symbol(accessorNames, Decl(constAssertions.ts, 101, 1))
>S : Symbol(S, Decl(constAssertions.ts, 103, 23))
>propName : Symbol(propName, Decl(constAssertions.ts, 103, 41))
>S : Symbol(S, Decl(constAssertions.ts, 103, 23))
return [`get-${propName}`, `set-${propName}`] as const;
>propName : Symbol(propName, Decl(constAssertions.ts, 103, 41))
>propName : Symbol(propName, Decl(constAssertions.ts, 103, 41))
>const : Symbol(const)
}
const ns1 = accessorNames('foo');
>ns1 : Symbol(ns1, Decl(constAssertions.ts, 107, 5))
>accessorNames : Symbol(accessorNames, Decl(constAssertions.ts, 101, 1))
|