Skip to content

Commit 2ceb350

Browse files
author
Andy
authored
Merge pull request microsoft#16059 from Microsoft/mappedTypeDeclarations
Set '.declarations' on a property of a homomorphic mapped type
2 parents ebbfca9 + 0d1e41d commit 2ceb350

9 files changed

+70
-42
lines changed

src/compiler/checker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5692,6 +5692,7 @@ namespace ts {
56925692
prop.type = propType;
56935693
if (propertySymbol) {
56945694
prop.syntheticOrigin = propertySymbol;
5695+
prop.declarations = propertySymbol.declarations;
56955696
}
56965697
members.set(propName, prop);
56975698
}

src/services/findAllReferences.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,12 @@ namespace ts.FindAllReferences.Core {
650650

651651
// If this is private property or method, the scope is the containing class
652652
if (flags & (SymbolFlags.Property | SymbolFlags.Method)) {
653-
const privateDeclaration = find(declarations, d => !!(getModifierFlags(d) & ModifierFlags.Private));
653+
const privateDeclaration = find(declarations, d => hasModifier(d, ModifierFlags.Private));
654654
if (privateDeclaration) {
655655
return getAncestor(privateDeclaration, SyntaxKind.ClassDeclaration);
656656
}
657+
// Else this is a public property and could be accessed from anywhere.
658+
return undefined;
657659
}
658660

659661
// If symbol is of object binding pattern element without property name we would want to
@@ -669,11 +671,6 @@ namespace ts.FindAllReferences.Core {
669671
return undefined;
670672
}
671673

672-
// If this is a synthetic property, it's a property and must be searched for globally.
673-
if ((flags & SymbolFlags.Transient && (<TransientSymbol>symbol).checkFlags & CheckFlags.Synthetic)) {
674-
return undefined;
675-
}
676-
677674
let scope: Node | undefined;
678675
for (const declaration of declarations) {
679676
const container = getContainerNode(declaration);

tests/baselines/reference/isomorphicMappedTypeInference.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ function f1() {
149149
let x: number = b.a.value;
150150
>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 45, 7))
151151
>b.a.value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15))
152-
>b.a : Symbol(a)
152+
>b.a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 39, 13))
153153
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 44, 7))
154-
>a : Symbol(a)
154+
>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 39, 13))
155155
>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15))
156156
}
157157

tests/baselines/reference/keyofAndIndexedAccess.symbols

+8-8
Original file line numberDiff line numberDiff line change
@@ -820,19 +820,19 @@ function f71(func: <T, U>(x: T, y: U) => Partial<T & U>) {
820820
>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
821821

822822
x.a; // number | undefined
823-
>x.a : Symbol(a)
823+
>x.a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 226, 18))
824824
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
825-
>a : Symbol(a)
825+
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 226, 18))
826826

827827
x.b; // string | undefined
828-
>x.b : Symbol(b)
828+
>x.b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 226, 24))
829829
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
830-
>b : Symbol(b)
830+
>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 226, 24))
831831

832832
x.c; // boolean | undefined
833-
>x.c : Symbol(c)
833+
>x.c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
834834
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
835-
>c : Symbol(c)
835+
>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
836836
}
837837

838838
function f72(func: <T, U, K extends keyof T | keyof U>(x: T, y: U, k: K) => (T & U)[K]) {
@@ -1951,11 +1951,11 @@ class AnotherSampleClass<T> extends SampleClass<T & Foo> {
19511951

19521952
this.props.foo.concat;
19531953
>this.props.foo.concat : Symbol(String.concat, Decl(lib.d.ts, --, --))
1954-
>this.props.foo : Symbol(foo)
1954+
>this.props.foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 536, 15))
19551955
>this.props : Symbol(SampleClass.props, Decl(keyofAndIndexedAccess.ts, 529, 22))
19561956
>this : Symbol(AnotherSampleClass, Decl(keyofAndIndexedAccess.ts, 540, 54))
19571957
>props : Symbol(SampleClass.props, Decl(keyofAndIndexedAccess.ts, 529, 22))
1958-
>foo : Symbol(foo)
1958+
>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 536, 15))
19591959
>concat : Symbol(String.concat, Decl(lib.d.ts, --, --))
19601960
}
19611961
}

tests/baselines/reference/mappedTypeModifiers.symbols

+8-8
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ function f1(x: Partial<Foo>) {
364364
>Foo : Symbol(Foo, Decl(mappedTypeModifiers.ts, 74, 30))
365365

366366
x.prop; // ok
367-
>x.prop : Symbol(prop)
367+
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
368368
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 78, 12))
369-
>prop : Symbol(prop)
369+
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
370370

371371
(x["other"] || 0).toFixed();
372372
>(x["other"] || 0).toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))
@@ -381,9 +381,9 @@ function f2(x: Readonly<Foo>) {
381381
>Foo : Symbol(Foo, Decl(mappedTypeModifiers.ts, 74, 30))
382382

383383
x.prop; // ok
384-
>x.prop : Symbol(prop)
384+
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
385385
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 83, 12))
386-
>prop : Symbol(prop)
386+
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
387387

388388
x["other"].toFixed();
389389
>x["other"].toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))
@@ -398,9 +398,9 @@ function f3(x: Boxified<Foo>) {
398398
>Foo : Symbol(Foo, Decl(mappedTypeModifiers.ts, 74, 30))
399399

400400
x.prop; // ok
401-
>x.prop : Symbol(prop)
401+
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
402402
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 88, 12))
403-
>prop : Symbol(prop)
403+
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
404404

405405
x["other"].x.toFixed();
406406
>x["other"].x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))
@@ -419,9 +419,9 @@ function f4(x: { [P in keyof Foo]: Foo[P] }) {
419419
>P : Symbol(P, Decl(mappedTypeModifiers.ts, 93, 18))
420420

421421
x.prop; // ok
422-
>x.prop : Symbol(prop)
422+
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
423423
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 93, 12))
424-
>prop : Symbol(prop)
424+
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
425425

426426
x["other"].toFixed();
427427
>x["other"].toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))

tests/baselines/reference/mappedTypes2.symbols

+10-10
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,16 @@ function f5(shape: Shape) {
313313
let name = p.name.get();
314314
>name : Symbol(name, Decl(mappedTypes2.ts, 84, 7))
315315
>p.name.get : Symbol(get, Decl(mappedTypes2.ts, 11, 17))
316-
>p.name : Symbol(name)
316+
>p.name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
317317
>p : Symbol(p, Decl(mappedTypes2.ts, 83, 9))
318-
>name : Symbol(name)
318+
>name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
319319
>get : Symbol(get, Decl(mappedTypes2.ts, 11, 17))
320320

321321
p.width.set(42);
322322
>p.width.set : Symbol(set, Decl(mappedTypes2.ts, 12, 13))
323-
>p.width : Symbol(width)
323+
>p.width : Symbol(width, Decl(mappedTypes2.ts, 36, 17))
324324
>p : Symbol(p, Decl(mappedTypes2.ts, 83, 9))
325-
>width : Symbol(width)
325+
>width : Symbol(width, Decl(mappedTypes2.ts, 36, 17))
326326
>set : Symbol(set, Decl(mappedTypes2.ts, 12, 13))
327327
}
328328

@@ -334,19 +334,19 @@ function f6(shape: DeepReadonly<Shape>) {
334334

335335
let name = shape.name; // string
336336
>name : Symbol(name, Decl(mappedTypes2.ts, 89, 7))
337-
>shape.name : Symbol(name)
337+
>shape.name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
338338
>shape : Symbol(shape, Decl(mappedTypes2.ts, 88, 12))
339-
>name : Symbol(name)
339+
>name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
340340

341341
let location = shape.location; // DeepReadonly<Point>
342342
>location : Symbol(location, Decl(mappedTypes2.ts, 90, 7))
343-
>shape.location : Symbol(location)
343+
>shape.location : Symbol(location, Decl(mappedTypes2.ts, 38, 19))
344344
>shape : Symbol(shape, Decl(mappedTypes2.ts, 88, 12))
345-
>location : Symbol(location)
345+
>location : Symbol(location, Decl(mappedTypes2.ts, 38, 19))
346346

347347
let x = location.x; // number
348348
>x : Symbol(x, Decl(mappedTypes2.ts, 91, 7))
349-
>location.x : Symbol(x)
349+
>location.x : Symbol(x, Decl(mappedTypes2.ts, 30, 17))
350350
>location : Symbol(location, Decl(mappedTypes2.ts, 90, 7))
351-
>x : Symbol(x)
351+
>x : Symbol(x, Decl(mappedTypes2.ts, 30, 17))
352352
}

tests/baselines/reference/mappedTypes3.symbols

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ function f1(b: Bacon) {
7171
let isPerfect = bb.isPerfect.value;
7272
>isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 23, 7))
7373
>bb.isPerfect.value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
74-
>bb.isPerfect : Symbol(isPerfect)
74+
>bb.isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 11, 17))
7575
>bb : Symbol(bb, Decl(mappedTypes3.ts, 22, 7))
76-
>isPerfect : Symbol(isPerfect)
76+
>isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 11, 17))
7777
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
7878

7979
let weight = bb.weight.value;
8080
>weight : Symbol(weight, Decl(mappedTypes3.ts, 24, 7))
8181
>bb.weight.value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
82-
>bb.weight : Symbol(weight)
82+
>bb.weight : Symbol(weight, Decl(mappedTypes3.ts, 12, 23))
8383
>bb : Symbol(bb, Decl(mappedTypes3.ts, 22, 7))
84-
>weight : Symbol(weight)
84+
>weight : Symbol(weight, Decl(mappedTypes3.ts, 12, 23))
8585
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
8686
}
8787

tests/baselines/reference/typeVariableTypeGuards.symbols

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ class A<P extends Partial<Foo>> {
2323
>doSomething : Symbol(A.doSomething, Decl(typeVariableTypeGuards.ts, 7, 22))
2424

2525
this.props.foo && this.props.foo()
26-
>this.props.foo : Symbol(foo)
26+
>this.props.foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
2727
>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
2828
>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1))
2929
>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
30-
>foo : Symbol(foo)
31-
>this.props.foo : Symbol(foo)
30+
>foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
31+
>this.props.foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
3232
>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
3333
>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1))
3434
>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
35-
>foo : Symbol(foo)
35+
>foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
3636
}
3737
}
3838

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <reference path="../fourslash.ts"/>
2+
3+
////interface Foo {
4+
//// /** Doc */
5+
//// bar: number;
6+
////}
7+
////
8+
////const f: Foo = { bar: 0 };
9+
////f./*f*/bar;
10+
////
11+
////const f2: { [TKey in keyof Foo]: string } = { bar: "0" };
12+
////f2./*f2*/bar;
13+
////
14+
////const f3 = { ...f };
15+
////f3./*f3*/bar;
16+
////
17+
////const f4 = { ...f2 };
18+
////f4./*f4*/bar;
19+
20+
goTo.marker("f");
21+
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");
22+
23+
goTo.marker("f2");
24+
verify.quickInfoIs("(property) bar: string", "Doc ");
25+
26+
goTo.marker("f3");
27+
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");
28+
29+
goTo.marker("f4");
30+
verify.quickInfoIs("(property) bar: string", "Doc ");

0 commit comments

Comments
 (0)