mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-20 10:29:36 -06:00
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:
parent
5cd49f6cbc
commit
7dcf11f139
@ -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;
|
||||
|
||||
|
||||
@ -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
tests/baselines/reference/renameForStringLiteral.baseline
Normal file
11
tests/baselines/reference/renameForStringLiteral.baseline
Normal file
@ -0,0 +1,11 @@
|
||||
/*====== /a.ts ======*/
|
||||
|
||||
interface Foo {
|
||||
property: "RENAME";
|
||||
}
|
||||
/**
|
||||
* @type {{ property: "foo"}}
|
||||
*/
|
||||
const obj: Foo = {
|
||||
property: "RENAME",
|
||||
}
|
||||
14
tests/cases/fourslash/findAllRefsForStringLiteral.ts
Normal file
14
tests/cases/fourslash/findAllRefsForStringLiteral.ts
Normal 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("");
|
||||
14
tests/cases/fourslash/renameForStringLiteral.ts
Normal file
14
tests/cases/fourslash/renameForStringLiteral.ts
Normal 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("", {});
|
||||
Loading…
x
Reference in New Issue
Block a user