|
| 1 | +=== tests/cases/conformance/controlFlow/controlFlowOptionalChain1.ts === |
| 2 | +type Shape = |
| 3 | +>Shape : Symbol(Shape, Decl(controlFlowOptionalChain1.ts, 0, 0)) |
| 4 | + |
| 5 | + | { type: 'rectangle', width: number, height: number } |
| 6 | +>type : Symbol(type, Decl(controlFlowOptionalChain1.ts, 1, 7)) |
| 7 | +>width : Symbol(width, Decl(controlFlowOptionalChain1.ts, 1, 26)) |
| 8 | +>height : Symbol(height, Decl(controlFlowOptionalChain1.ts, 1, 41)) |
| 9 | + |
| 10 | + | { type: 'circle', radius: number } |
| 11 | +>type : Symbol(type, Decl(controlFlowOptionalChain1.ts, 2, 7)) |
| 12 | +>radius : Symbol(radius, Decl(controlFlowOptionalChain1.ts, 2, 23)) |
| 13 | + |
| 14 | +declare function assertUndefined(v: undefined): void |
| 15 | +>assertUndefined : Symbol(assertUndefined, Decl(controlFlowOptionalChain1.ts, 2, 40)) |
| 16 | +>v : Symbol(v, Decl(controlFlowOptionalChain1.ts, 4, 33)) |
| 17 | + |
| 18 | +function getArea(shape?: Shape) { |
| 19 | +>getArea : Symbol(getArea, Decl(controlFlowOptionalChain1.ts, 4, 52)) |
| 20 | +>shape : Symbol(shape, Decl(controlFlowOptionalChain1.ts, 6, 17)) |
| 21 | +>Shape : Symbol(Shape, Decl(controlFlowOptionalChain1.ts, 0, 0)) |
| 22 | + |
| 23 | + switch (shape?.type) { |
| 24 | +>shape?.type : Symbol(type, Decl(controlFlowOptionalChain1.ts, 1, 7), Decl(controlFlowOptionalChain1.ts, 2, 7)) |
| 25 | +>shape : Symbol(shape, Decl(controlFlowOptionalChain1.ts, 6, 17)) |
| 26 | +>type : Symbol(type, Decl(controlFlowOptionalChain1.ts, 1, 7), Decl(controlFlowOptionalChain1.ts, 2, 7)) |
| 27 | + |
| 28 | + case 'circle': |
| 29 | + return Math.PI * shape.radius ** 2 |
| 30 | +>Math.PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) |
| 31 | +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 32 | +>PI : Symbol(Math.PI, Decl(lib.es5.d.ts, --, --)) |
| 33 | +>shape.radius : Symbol(radius, Decl(controlFlowOptionalChain1.ts, 2, 23)) |
| 34 | +>shape : Symbol(shape, Decl(controlFlowOptionalChain1.ts, 6, 17)) |
| 35 | +>radius : Symbol(radius, Decl(controlFlowOptionalChain1.ts, 2, 23)) |
| 36 | + |
| 37 | + case 'rectangle': |
| 38 | + return shape.width * shape.height |
| 39 | +>shape.width : Symbol(width, Decl(controlFlowOptionalChain1.ts, 1, 26)) |
| 40 | +>shape : Symbol(shape, Decl(controlFlowOptionalChain1.ts, 6, 17)) |
| 41 | +>width : Symbol(width, Decl(controlFlowOptionalChain1.ts, 1, 26)) |
| 42 | +>shape.height : Symbol(height, Decl(controlFlowOptionalChain1.ts, 1, 41)) |
| 43 | +>shape : Symbol(shape, Decl(controlFlowOptionalChain1.ts, 6, 17)) |
| 44 | +>height : Symbol(height, Decl(controlFlowOptionalChain1.ts, 1, 41)) |
| 45 | + |
| 46 | + default: |
| 47 | + return assertUndefined(shape) |
| 48 | +>assertUndefined : Symbol(assertUndefined, Decl(controlFlowOptionalChain1.ts, 2, 40)) |
| 49 | +>shape : Symbol(shape, Decl(controlFlowOptionalChain1.ts, 6, 17)) |
| 50 | + } |
| 51 | +} |
| 52 | + |
0 commit comments