Skip to content

Commit 47452cf

Browse files
committed
tweak
1 parent 594a01b commit 47452cf

3 files changed

Lines changed: 111 additions & 5 deletions

File tree

src/services/goToDefinition.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,8 @@ function getDefinitionFromObjectLiteralElement(typeChecker: TypeChecker, node: N
316316
const contextualType = element && typeChecker.getContextualType(element.parent);
317317
if (contextualType) {
318318
let properties = getPropertySymbolsFromContextualType(element, typeChecker, contextualType, /*unionSymbolOk*/ false);
319-
if (properties.length === 1) {
320-
const declaration = properties[0].valueDeclaration;
321-
const withoutNodeInferencesType = declaration && isObjectLiteralExpression(declaration.parent) && isObjectLiteralElementLike(declaration) && declaration.name === node ?
322-
typeChecker.getContextualType(element.parent, ContextFlags.IgnoreNodeInferences) :
323-
undefined;
319+
if (some(properties, p => !!(p.valueDeclaration && isObjectLiteralExpression(p.valueDeclaration.parent) && isObjectLiteralElementLike(p.valueDeclaration) && p.valueDeclaration.name === node))) {
320+
const withoutNodeInferencesType = typeChecker.getContextualType(element.parent, ContextFlags.IgnoreNodeInferences);
324321
if (withoutNodeInferencesType) {
325322
const withoutNodeInferencesProperties = getPropertySymbolsFromContextualType(element, typeChecker, withoutNodeInferencesType, /*unionSymbolOk*/ false);
326323
if (withoutNodeInferencesProperties.length) {
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// === goToDefinition ===
2+
// === /tests/cases/fourslash/goToDefinitionObjectLiteralProperties3.ts ===
3+
// type A = {
4+
// <|[|{| defId: 0 |}foo|]: unknown;|>
5+
// };
6+
//
7+
// type B = {
8+
// <|[|{| defId: 1 |}foo|]?: unknown;|>
9+
// bar: unknown;
10+
// };
11+
//
12+
// function test1(arg: A | B) {}
13+
//
14+
// test1({
15+
// foo/*GOTO DEF*/: 1,
16+
// });
17+
//
18+
// function test2<T extends A>(arg: T | B) {}
19+
// --- (line: 17) skipped ---
20+
21+
// === Details ===
22+
[
23+
{
24+
"defId": 0,
25+
"kind": "property",
26+
"name": "foo",
27+
"containerName": "__type",
28+
"isLocal": false,
29+
"isAmbient": false,
30+
"unverified": false
31+
},
32+
{
33+
"defId": 1,
34+
"kind": "property",
35+
"name": "foo",
36+
"containerName": "__type",
37+
"isLocal": false,
38+
"isAmbient": false,
39+
"unverified": false
40+
}
41+
]
42+
43+
44+
45+
// === goToDefinition ===
46+
// === /tests/cases/fourslash/goToDefinitionObjectLiteralProperties3.ts ===
47+
// type A = {
48+
// <|[|{| defId: 0 |}foo|]: unknown;|>
49+
// };
50+
//
51+
// type B = {
52+
// <|[|{| defId: 1 |}foo|]?: unknown;|>
53+
// bar: unknown;
54+
// };
55+
//
56+
// --- (line: 10) skipped ---
57+
58+
// --- (line: 15) skipped ---
59+
// function test2<T extends A>(arg: T | B) {}
60+
//
61+
// test2({
62+
// foo/*GOTO DEF*/: 2,
63+
// });
64+
65+
// === Details ===
66+
[
67+
{
68+
"defId": 0,
69+
"kind": "property",
70+
"name": "foo",
71+
"containerName": "__type",
72+
"isLocal": false,
73+
"isAmbient": false,
74+
"unverified": false
75+
},
76+
{
77+
"defId": 1,
78+
"kind": "property",
79+
"name": "foo",
80+
"containerName": "__type",
81+
"isLocal": false,
82+
"isAmbient": false,
83+
"unverified": false
84+
}
85+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
//// type A = {
4+
//// foo: unknown;
5+
//// };
6+
////
7+
//// type B = {
8+
//// foo?: unknown;
9+
//// bar: unknown;
10+
//// };
11+
////
12+
//// function test1(arg: A | B) {}
13+
////
14+
//// test1({
15+
//// foo/*1*/: 1,
16+
//// });
17+
////
18+
//// function test2<T extends A>(arg: T | B) {}
19+
////
20+
//// test2({
21+
//// foo/*2*/: 2,
22+
//// });
23+
24+
verify.baselineGoToDefinition("1", "2");

0 commit comments

Comments
 (0)