Skip to content

Set '.declarations' on a property of a homomorphic mapped type #16059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5690,6 +5690,7 @@ namespace ts {
prop.type = propType;
if (propertySymbol) {
prop.syntheticOrigin = propertySymbol;
prop.declarations = propertySymbol.declarations;
}
members.set(propName, prop);
}
Expand Down
9 changes: 3 additions & 6 deletions src/services/findAllReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,12 @@ namespace ts.FindAllReferences.Core {

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

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

// If this is a synthetic property, it's a property and must be searched for globally.
if ((flags & SymbolFlags.Transient && (<TransientSymbol>symbol).checkFlags & CheckFlags.Synthetic)) {
return undefined;
}

let scope: Node | undefined;
for (const declaration of declarations) {
const container = getContainerNode(declaration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ function f1() {
let x: number = b.a.value;
>x : Symbol(x, Decl(isomorphicMappedTypeInference.ts, 45, 7))
>b.a.value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15))
>b.a : Symbol(a)
>b.a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 39, 13))
>b : Symbol(b, Decl(isomorphicMappedTypeInference.ts, 44, 7))
>a : Symbol(a)
>a : Symbol(a, Decl(isomorphicMappedTypeInference.ts, 39, 13))
>value : Symbol(value, Decl(isomorphicMappedTypeInference.ts, 0, 15))
}

Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/keyofAndIndexedAccess.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -820,19 +820,19 @@ function f71(func: <T, U>(x: T, y: U) => Partial<T & U>) {
>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))

x.a; // number | undefined
>x.a : Symbol(a)
>x.a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 226, 18))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
>a : Symbol(a)
>a : Symbol(a, Decl(keyofAndIndexedAccess.ts, 226, 18))

x.b; // string | undefined
>x.b : Symbol(b)
>x.b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 226, 24))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
>b : Symbol(b)
>b : Symbol(b, Decl(keyofAndIndexedAccess.ts, 226, 24))

x.c; // boolean | undefined
>x.c : Symbol(c)
>x.c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 226, 7))
>c : Symbol(c)
>c : Symbol(c, Decl(keyofAndIndexedAccess.ts, 226, 40))
}

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

this.props.foo.concat;
>this.props.foo.concat : Symbol(String.concat, Decl(lib.d.ts, --, --))
>this.props.foo : Symbol(foo)
>this.props.foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 536, 15))
>this.props : Symbol(SampleClass.props, Decl(keyofAndIndexedAccess.ts, 529, 22))
>this : Symbol(AnotherSampleClass, Decl(keyofAndIndexedAccess.ts, 540, 54))
>props : Symbol(SampleClass.props, Decl(keyofAndIndexedAccess.ts, 529, 22))
>foo : Symbol(foo)
>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 536, 15))
>concat : Symbol(String.concat, Decl(lib.d.ts, --, --))
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/mappedTypeModifiers.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ function f1(x: Partial<Foo>) {
>Foo : Symbol(Foo, Decl(mappedTypeModifiers.ts, 74, 30))

x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 78, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))

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

x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 83, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))

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

x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 88, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))

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

x.prop; // ok
>x.prop : Symbol(prop)
>x.prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))
>x : Symbol(x, Decl(mappedTypeModifiers.ts, 93, 12))
>prop : Symbol(prop)
>prop : Symbol(prop, Decl(mappedTypeModifiers.ts, 76, 12))

x["other"].toFixed();
>x["other"].toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --))
Expand Down
20 changes: 10 additions & 10 deletions tests/baselines/reference/mappedTypes2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,16 @@ function f5(shape: Shape) {
let name = p.name.get();
>name : Symbol(name, Decl(mappedTypes2.ts, 84, 7))
>p.name.get : Symbol(get, Decl(mappedTypes2.ts, 11, 17))
>p.name : Symbol(name)
>p.name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
>p : Symbol(p, Decl(mappedTypes2.ts, 83, 9))
>name : Symbol(name)
>name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
>get : Symbol(get, Decl(mappedTypes2.ts, 11, 17))

p.width.set(42);
>p.width.set : Symbol(set, Decl(mappedTypes2.ts, 12, 13))
>p.width : Symbol(width)
>p.width : Symbol(width, Decl(mappedTypes2.ts, 36, 17))
>p : Symbol(p, Decl(mappedTypes2.ts, 83, 9))
>width : Symbol(width)
>width : Symbol(width, Decl(mappedTypes2.ts, 36, 17))
>set : Symbol(set, Decl(mappedTypes2.ts, 12, 13))
}

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

let name = shape.name; // string
>name : Symbol(name, Decl(mappedTypes2.ts, 89, 7))
>shape.name : Symbol(name)
>shape.name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 88, 12))
>name : Symbol(name)
>name : Symbol(name, Decl(mappedTypes2.ts, 35, 17))

let location = shape.location; // DeepReadonly<Point>
>location : Symbol(location, Decl(mappedTypes2.ts, 90, 7))
>shape.location : Symbol(location)
>shape.location : Symbol(location, Decl(mappedTypes2.ts, 38, 19))
>shape : Symbol(shape, Decl(mappedTypes2.ts, 88, 12))
>location : Symbol(location)
>location : Symbol(location, Decl(mappedTypes2.ts, 38, 19))

let x = location.x; // number
>x : Symbol(x, Decl(mappedTypes2.ts, 91, 7))
>location.x : Symbol(x)
>location.x : Symbol(x, Decl(mappedTypes2.ts, 30, 17))
>location : Symbol(location, Decl(mappedTypes2.ts, 90, 7))
>x : Symbol(x)
>x : Symbol(x, Decl(mappedTypes2.ts, 30, 17))
}
8 changes: 4 additions & 4 deletions tests/baselines/reference/mappedTypes3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ function f1(b: Bacon) {
let isPerfect = bb.isPerfect.value;
>isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 23, 7))
>bb.isPerfect.value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
>bb.isPerfect : Symbol(isPerfect)
>bb.isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 11, 17))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 22, 7))
>isPerfect : Symbol(isPerfect)
>isPerfect : Symbol(isPerfect, Decl(mappedTypes3.ts, 11, 17))
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))

let weight = bb.weight.value;
>weight : Symbol(weight, Decl(mappedTypes3.ts, 24, 7))
>bb.weight.value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
>bb.weight : Symbol(weight)
>bb.weight : Symbol(weight, Decl(mappedTypes3.ts, 12, 23))
>bb : Symbol(bb, Decl(mappedTypes3.ts, 22, 7))
>weight : Symbol(weight)
>weight : Symbol(weight, Decl(mappedTypes3.ts, 12, 23))
>value : Symbol(Box.value, Decl(mappedTypes3.ts, 0, 14))
}

Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/typeVariableTypeGuards.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class A<P extends Partial<Foo>> {
>doSomething : Symbol(A.doSomething, Decl(typeVariableTypeGuards.ts, 7, 22))

this.props.foo && this.props.foo()
>this.props.foo : Symbol(foo)
>this.props.foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1))
>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>foo : Symbol(foo)
>this.props.foo : Symbol(foo)
>foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
>this.props.foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
>this.props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>this : Symbol(A, Decl(typeVariableTypeGuards.ts, 4, 1))
>props : Symbol(A.props, Decl(typeVariableTypeGuards.ts, 6, 33))
>foo : Symbol(foo)
>foo : Symbol(foo, Decl(typeVariableTypeGuards.ts, 2, 15))
}
}

Expand Down
30 changes: 30 additions & 0 deletions tests/cases/fourslash/server/quickInfoMappedSpreadTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference path="../fourslash.ts"/>

////interface Foo {
//// /** Doc */
//// bar: number;
////}
////
////const f: Foo = { bar: 0 };
////f./*f*/bar;
////
////const f2: { [TKey in keyof Foo]: string } = { bar: "0" };
////f2./*f2*/bar;
////
////const f3 = { ...f };
////f3./*f3*/bar;
////
////const f4 = { ...f2 };
////f4./*f4*/bar;

goTo.marker("f");
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");

goTo.marker("f2");
verify.quickInfoIs("(property) bar: string", "Doc ");

goTo.marker("f3");
verify.quickInfoIs("(property) Foo.bar: number", "Doc ");

goTo.marker("f4");
verify.quickInfoIs("(property) bar: string", "Doc ");