Skip to content

Commit

Permalink
fix(50750): Object type literal with string literal property in conte…
Browse files Browse the repository at this point in the history
…xtual typing position causes language service error on all literal type references (#50757)

* fix(50750): skip unbound symbols from JSDoc tags in typescript

* skip contextual type checking in JsDoc for TypeScript files
  • Loading branch information
a-tarasyuk authored Oct 3, 2022
1 parent 5cd49f6 commit 7dcf11f
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ namespace ts {
}

export function getContextualTypeFromParentOrAncestorTypeNode(node: Expression, checker: TypeChecker): Type | undefined {
if (node.flags & (NodeFlags.JSDoc & ~NodeFlags.JavaScriptFile)) return undefined;

const contextualType = getContextualTypeFromParent(node, checker);
if (contextualType) return contextualType;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// === /a.ts ===
// interface Foo {
// property: /*FIND ALL REFS*/"[|foo|]";
// }
// /**
// * @type {{ property: "foo"}}
// */
// const obj: Foo = {
// property: "[|foo|]",
// }

[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/a.ts",
"kind": "var",
"name": "foo",
"textSpan": {
"start": 31,
"length": 3
},
"displayParts": [
{
"text": "\"foo\"",
"kind": "stringLiteral"
}
]
},
"references": [
{
"textSpan": {
"start": 31,
"length": 3
},
"fileName": "/a.ts",
"isWriteAccess": false,
"isInString": true
},
{
"textSpan": {
"start": 111,
"length": 3
},
"fileName": "/a.ts",
"isWriteAccess": false,
"isInString": true
}
]
}
]
11 changes: 11 additions & 0 deletions tests/baselines/reference/renameForStringLiteral.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*====== /a.ts ======*/

interface Foo {
property: "RENAME";
}
/**
* @type {{ property: "foo"}}
*/
const obj: Foo = {
property: "RENAME",
}
14 changes: 14 additions & 0 deletions tests/cases/fourslash/findAllRefsForStringLiteral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

// @filename: /a.ts
////interface Foo {
//// property: /**/"foo";
////}
/////**
//// * @type {{ property: "foo"}}
//// */
////const obj: Foo = {
//// property: "foo",
////}

verify.baselineFindAllReferences("");
14 changes: 14 additions & 0 deletions tests/cases/fourslash/renameForStringLiteral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

// @filename: /a.ts
////interface Foo {
//// property: /**/"foo";
////}
/////**
//// * @type {{ property: "foo"}}
//// */
////const obj: Foo = {
//// property: "foo",
////}

verify.baselineRename("", {});

0 comments on commit 7dcf11f

Please sign in to comment.