fix(50750): Object type literal with string literal property in contextual 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
This commit is contained in:
Oleksandr T 2022-10-04 01:57:32 +03:00 committed by GitHub
parent 5cd49f6cbc
commit 7dcf11f139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 0 deletions

View File

@ -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;

View File

@ -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
}
]
}
]

View File

@ -0,0 +1,11 @@
/*====== /a.ts ======*/
interface Foo {
property: "RENAME";
}
/**
* @type {{ property: "foo"}}
*/
const obj: Foo = {
property: "RENAME",
}

View File

@ -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("");

View File

@ -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("", {});