|
| 1 | +=== tests/cases/compiler/narrowingByDiscriminantInLoop.ts === |
| 2 | +// Repro from #9977 |
| 3 | + |
| 4 | +type IDLMemberTypes = OperationMemberType | ConstantMemberType; |
| 5 | +>IDLMemberTypes : Symbol(IDLMemberTypes, Decl(narrowingByDiscriminantInLoop.ts, 0, 0)) |
| 6 | +>OperationMemberType : Symbol(OperationMemberType, Decl(narrowingByDiscriminantInLoop.ts, 10, 1)) |
| 7 | +>ConstantMemberType : Symbol(ConstantMemberType, Decl(narrowingByDiscriminantInLoop.ts, 15, 1)) |
| 8 | + |
| 9 | +interface IDLTypeDescription { |
| 10 | +>IDLTypeDescription : Symbol(IDLTypeDescription, Decl(narrowingByDiscriminantInLoop.ts, 2, 63)) |
| 11 | + |
| 12 | + origin: string; |
| 13 | +>origin : Symbol(IDLTypeDescription.origin, Decl(narrowingByDiscriminantInLoop.ts, 4, 30)) |
| 14 | +} |
| 15 | + |
| 16 | +interface InterfaceType { |
| 17 | +>InterfaceType : Symbol(InterfaceType, Decl(narrowingByDiscriminantInLoop.ts, 6, 1)) |
| 18 | + |
| 19 | + members: IDLMemberTypes[]; |
| 20 | +>members : Symbol(InterfaceType.members, Decl(narrowingByDiscriminantInLoop.ts, 8, 25)) |
| 21 | +>IDLMemberTypes : Symbol(IDLMemberTypes, Decl(narrowingByDiscriminantInLoop.ts, 0, 0)) |
| 22 | +} |
| 23 | + |
| 24 | +interface OperationMemberType { |
| 25 | +>OperationMemberType : Symbol(OperationMemberType, Decl(narrowingByDiscriminantInLoop.ts, 10, 1)) |
| 26 | + |
| 27 | + type: "operation"; |
| 28 | +>type : Symbol(OperationMemberType.type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31)) |
| 29 | + |
| 30 | + idlType: IDLTypeDescription | null; |
| 31 | +>idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 32 | +>IDLTypeDescription : Symbol(IDLTypeDescription, Decl(narrowingByDiscriminantInLoop.ts, 2, 63)) |
| 33 | +} |
| 34 | + |
| 35 | +interface ConstantMemberType { |
| 36 | +>ConstantMemberType : Symbol(ConstantMemberType, Decl(narrowingByDiscriminantInLoop.ts, 15, 1)) |
| 37 | + |
| 38 | + type: "const"; |
| 39 | +>type : Symbol(ConstantMemberType.type, Decl(narrowingByDiscriminantInLoop.ts, 17, 30)) |
| 40 | + |
| 41 | + idlType: string; |
| 42 | +>idlType : Symbol(ConstantMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 18, 18)) |
| 43 | +} |
| 44 | + |
| 45 | +function insertInterface(callbackType: InterfaceType) { |
| 46 | +>insertInterface : Symbol(insertInterface, Decl(narrowingByDiscriminantInLoop.ts, 20, 1)) |
| 47 | +>callbackType : Symbol(callbackType, Decl(narrowingByDiscriminantInLoop.ts, 22, 25)) |
| 48 | +>InterfaceType : Symbol(InterfaceType, Decl(narrowingByDiscriminantInLoop.ts, 6, 1)) |
| 49 | + |
| 50 | + for (const memberType of callbackType.members) { |
| 51 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 23, 14)) |
| 52 | +>callbackType.members : Symbol(InterfaceType.members, Decl(narrowingByDiscriminantInLoop.ts, 8, 25)) |
| 53 | +>callbackType : Symbol(callbackType, Decl(narrowingByDiscriminantInLoop.ts, 22, 25)) |
| 54 | +>members : Symbol(InterfaceType.members, Decl(narrowingByDiscriminantInLoop.ts, 8, 25)) |
| 55 | + |
| 56 | + if (memberType.type === "const") { |
| 57 | +>memberType.type : Symbol(type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31), Decl(narrowingByDiscriminantInLoop.ts, 17, 30)) |
| 58 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 23, 14)) |
| 59 | +>type : Symbol(type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31), Decl(narrowingByDiscriminantInLoop.ts, 17, 30)) |
| 60 | + |
| 61 | + memberType.idlType; // string |
| 62 | +>memberType.idlType : Symbol(ConstantMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 18, 18)) |
| 63 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 23, 14)) |
| 64 | +>idlType : Symbol(ConstantMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 18, 18)) |
| 65 | + } |
| 66 | + else if (memberType.type === "operation") { |
| 67 | +>memberType.type : Symbol(OperationMemberType.type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31)) |
| 68 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 23, 14)) |
| 69 | +>type : Symbol(OperationMemberType.type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31)) |
| 70 | + |
| 71 | + memberType.idlType.origin; // string |
| 72 | +>memberType.idlType.origin : Symbol(IDLTypeDescription.origin, Decl(narrowingByDiscriminantInLoop.ts, 4, 30)) |
| 73 | +>memberType.idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 74 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 23, 14)) |
| 75 | +>idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 76 | +>origin : Symbol(IDLTypeDescription.origin, Decl(narrowingByDiscriminantInLoop.ts, 4, 30)) |
| 77 | + |
| 78 | + (memberType.idlType as IDLTypeDescription); |
| 79 | +>memberType.idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 80 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 23, 14)) |
| 81 | +>idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 82 | +>IDLTypeDescription : Symbol(IDLTypeDescription, Decl(narrowingByDiscriminantInLoop.ts, 2, 63)) |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +function insertInterface2(callbackType: InterfaceType) { |
| 88 | +>insertInterface2 : Symbol(insertInterface2, Decl(narrowingByDiscriminantInLoop.ts, 32, 1)) |
| 89 | +>callbackType : Symbol(callbackType, Decl(narrowingByDiscriminantInLoop.ts, 34, 26)) |
| 90 | +>InterfaceType : Symbol(InterfaceType, Decl(narrowingByDiscriminantInLoop.ts, 6, 1)) |
| 91 | + |
| 92 | + for (const memberType of callbackType.members) { |
| 93 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 35, 14)) |
| 94 | +>callbackType.members : Symbol(InterfaceType.members, Decl(narrowingByDiscriminantInLoop.ts, 8, 25)) |
| 95 | +>callbackType : Symbol(callbackType, Decl(narrowingByDiscriminantInLoop.ts, 34, 26)) |
| 96 | +>members : Symbol(InterfaceType.members, Decl(narrowingByDiscriminantInLoop.ts, 8, 25)) |
| 97 | + |
| 98 | + if (memberType.type === "operation") { |
| 99 | +>memberType.type : Symbol(type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31), Decl(narrowingByDiscriminantInLoop.ts, 17, 30)) |
| 100 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 35, 14)) |
| 101 | +>type : Symbol(type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31), Decl(narrowingByDiscriminantInLoop.ts, 17, 30)) |
| 102 | + |
| 103 | + memberType.idlType.origin; // string |
| 104 | +>memberType.idlType.origin : Symbol(IDLTypeDescription.origin, Decl(narrowingByDiscriminantInLoop.ts, 4, 30)) |
| 105 | +>memberType.idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 106 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 35, 14)) |
| 107 | +>idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 108 | +>origin : Symbol(IDLTypeDescription.origin, Decl(narrowingByDiscriminantInLoop.ts, 4, 30)) |
| 109 | + } |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +function foo(memberType: IDLMemberTypes) { |
| 114 | +>foo : Symbol(foo, Decl(narrowingByDiscriminantInLoop.ts, 40, 1)) |
| 115 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 42, 13)) |
| 116 | +>IDLMemberTypes : Symbol(IDLMemberTypes, Decl(narrowingByDiscriminantInLoop.ts, 0, 0)) |
| 117 | + |
| 118 | + if (memberType.type === "const") { |
| 119 | +>memberType.type : Symbol(type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31), Decl(narrowingByDiscriminantInLoop.ts, 17, 30)) |
| 120 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 42, 13)) |
| 121 | +>type : Symbol(type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31), Decl(narrowingByDiscriminantInLoop.ts, 17, 30)) |
| 122 | + |
| 123 | + memberType.idlType; // string |
| 124 | +>memberType.idlType : Symbol(ConstantMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 18, 18)) |
| 125 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 42, 13)) |
| 126 | +>idlType : Symbol(ConstantMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 18, 18)) |
| 127 | + } |
| 128 | + else if (memberType.type === "operation") { |
| 129 | +>memberType.type : Symbol(OperationMemberType.type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31)) |
| 130 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 42, 13)) |
| 131 | +>type : Symbol(OperationMemberType.type, Decl(narrowingByDiscriminantInLoop.ts, 12, 31)) |
| 132 | + |
| 133 | + memberType.idlType.origin; // string |
| 134 | +>memberType.idlType.origin : Symbol(IDLTypeDescription.origin, Decl(narrowingByDiscriminantInLoop.ts, 4, 30)) |
| 135 | +>memberType.idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 136 | +>memberType : Symbol(memberType, Decl(narrowingByDiscriminantInLoop.ts, 42, 13)) |
| 137 | +>idlType : Symbol(OperationMemberType.idlType, Decl(narrowingByDiscriminantInLoop.ts, 13, 22)) |
| 138 | +>origin : Symbol(IDLTypeDescription.origin, Decl(narrowingByDiscriminantInLoop.ts, 4, 30)) |
| 139 | + } |
| 140 | +} |
0 commit comments