Skip to content

fix(52594): this incorrectly applies in TS files in typeToString #52610

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
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7307,7 +7307,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (signature.thisParameter) {
return symbolToParameterDeclaration(signature.thisParameter, context);
}
if (signature.declaration) {
if (signature.declaration && isInJSFile(signature.declaration)) {
const thisTag = getJSDocThisTag(signature.declaration);
if (thisTag && thisTag.typeExpression) {
return factory.createParameterDeclaration(
Expand Down
68 changes: 68 additions & 0 deletions tests/baselines/reference/quickInfoJsDocThisTag.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
=== /a.ts ===
// /** @this {number} */
// function f() {
// ^
// | ----------------------------------------------------------------------
// | function f(): void
// | @this
// | ----------------------------------------------------------------------
// this
// }

[
{
"marker": {
"fileName": "/a.ts",
"position": 32,
"name": ""
},
"item": {
"kind": "function",
"kindModifiers": "",
"textSpan": {
"start": 31,
"length": 1
},
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "f",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "this"
}
]
}
}
]
4 changes: 2 additions & 2 deletions tests/baselines/reference/thisInFunctionCall.types
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Test {

/** @this {Test} */
function (d) {
>function (d) { console.log(d === this.data.length) } : (this: Test, d: number) => void
>function (d) { console.log(d === this.data.length) } : (d: number) => void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test need to be preserved somewhere with a .js extension so we can still cover this case, or do we have another test which does this correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test for the JavaScript case.

>d : number

console.log(d === this.data.length)
Expand Down Expand Up @@ -117,7 +117,7 @@ class Test {

/** @this {Test} */
function (d) {
>function (d) { return d === this.data.length } : (this: Test, d: number) => boolean
>function (d) { return d === this.data.length } : (d: number) => boolean
>d : number

return d === this.data.length
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/fourslash/quickInfoJsDocThisTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />
// @strict: true
// @filename: /a.ts
/////** @this {number} */
////function f/**/() {
//// this
////}

verify.baselineQuickInfo();