2014-10-09 08:21:56 +02:00
|
|
|
/// <reference path='fourslash.ts'/>
|
|
|
|
|
|
|
|
////interface A {
|
|
|
|
//// a: number;
|
2019-06-13 21:25:02 +02:00
|
|
|
//// [|[|{| "isDefinition": true, "contextRangeIndex": 0 |}common|]: string;|]
|
2014-10-09 08:21:56 +02:00
|
|
|
////}
|
|
|
|
////
|
|
|
|
////interface B {
|
|
|
|
//// b: number;
|
2019-06-13 21:25:02 +02:00
|
|
|
//// [|[|{| "isDefinition": true, "contextRangeIndex": 2 |}common|]: number;|]
|
2014-10-09 08:21:56 +02:00
|
|
|
////}
|
|
|
|
////
|
|
|
|
////// Assignment
|
2019-06-13 21:25:02 +02:00
|
|
|
////var v1: A | B = { a: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "string", "contextRangeIndex": 4 |}common|]: ""|] };
|
|
|
|
////var v2: A | B = { b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "contextRangeIndex": 6 |}common|]: 3|] };
|
2014-10-09 08:21:56 +02:00
|
|
|
////
|
|
|
|
////// Function call
|
|
|
|
////function consumer(f: A | B) { }
|
2019-06-13 21:25:02 +02:00
|
|
|
////consumer({ a: 0, b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "contextRangeIndex": 8 |}common|]: 1|] });
|
2014-10-09 08:21:56 +02:00
|
|
|
////
|
2017-01-27 17:59:33 +01:00
|
|
|
////// Type cast
|
2019-06-13 21:25:02 +02:00
|
|
|
////var c = <A | B> { [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "contextRangeIndex": 10 |}common|]: 0|], b: 0 };
|
2014-10-09 08:21:56 +02:00
|
|
|
////
|
|
|
|
////// Array literal
|
2019-06-13 21:25:02 +02:00
|
|
|
////var ar: Array<A|B> = [{ a: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "string", "contextRangeIndex": 12 |}common|]: ""|] }, { b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "contextRangeIndex": 14 |}common|]: 0|] }];
|
2014-10-09 08:21:56 +02:00
|
|
|
////
|
|
|
|
////// Nested object literal
|
2019-06-13 21:25:02 +02:00
|
|
|
////var ob: { aorb: A|B } = { aorb: { b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "contextRangeIndex": 16 |}common|]: 0|] } };
|
2014-10-09 08:21:56 +02:00
|
|
|
////
|
|
|
|
////// Widened type
|
2019-06-13 21:25:02 +02:00
|
|
|
////var w: A|B = { a:0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined", "contextRangeIndex": 18 |}common|]: undefined|] };
|
2014-10-09 08:21:56 +02:00
|
|
|
////
|
|
|
|
////// Untped -- should not be included
|
|
|
|
////var u1 = { a: 0, b: 0, common: "" };
|
|
|
|
////var u2 = { b: 0, common: 0 };
|
|
|
|
|
2019-06-03 23:13:47 +02:00
|
|
|
const [aCommon, bCommon, ...unionRefs] = test.rangesByText().get("common");
|
2018-03-19 19:58:20 +01:00
|
|
|
verify.referenceGroups(aCommon, [
|
|
|
|
{ definition: "(property) A.common: string", ranges: [aCommon] },
|
|
|
|
{ definition: "(property) common: string | number", ranges: unionRefs },
|
|
|
|
]);
|
|
|
|
verify.referenceGroups(bCommon, [
|
|
|
|
{ definition: "(property) B.common: number", ranges: [bCommon] },
|
|
|
|
{ definition: "(property) common: string | number", ranges: unionRefs },
|
|
|
|
]);
|
2018-04-06 00:00:14 +02:00
|
|
|
verify.referenceGroups(unionRefs, [
|
|
|
|
{ definition: "(property) A.common: string", ranges: [aCommon] },
|
|
|
|
{ definition: "(property) B.common: number", ranges: [bCommon] },
|
|
|
|
{ definition: `(property) common: string | number`, ranges: unionRefs },
|
|
|
|
]);
|