mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
fix(55796): JSDoc does not support @this when using an arrow function as method in class (#55877)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
parent
781cc19b32
commit
5449489238
@ -780,6 +780,7 @@ import {
|
||||
JSDocSatisfiesTag,
|
||||
JSDocSignature,
|
||||
JSDocTemplateTag,
|
||||
JSDocThisTag,
|
||||
JSDocTypeAssertion,
|
||||
JSDocTypedefTag,
|
||||
JSDocTypeExpression,
|
||||
@ -41240,6 +41241,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
function checkJSDocParameterTag(node: JSDocParameterTag) {
|
||||
checkSourceElement(node.typeExpression);
|
||||
}
|
||||
|
||||
function checkJSDocPropertyTag(node: JSDocPropertyTag) {
|
||||
checkSourceElement(node.typeExpression);
|
||||
}
|
||||
@ -41255,6 +41257,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
function checkJSDocThisTag(node: JSDocThisTag) {
|
||||
const host = getEffectiveJSDocHost(node);
|
||||
if (host && isArrowFunction(host)) {
|
||||
error(node.tagName, Diagnostics.An_arrow_function_cannot_have_a_this_parameter);
|
||||
}
|
||||
}
|
||||
|
||||
function checkJSDocImplementsTag(node: JSDocImplementsTag): void {
|
||||
const classLike = getEffectiveJSDocHost(node);
|
||||
if (!classLike || !isClassDeclaration(classLike) && !isClassExpression(classLike)) {
|
||||
@ -45973,6 +45982,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return checkJSDocAccessibilityModifiers(node as JSDocPublicTag | JSDocProtectedTag | JSDocPrivateTag);
|
||||
case SyntaxKind.JSDocSatisfiesTag:
|
||||
return checkJSDocSatisfiesTag(node as JSDocSatisfiesTag);
|
||||
case SyntaxKind.JSDocThisTag:
|
||||
return checkJSDocThisTag(node as JSDocThisTag);
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
return checkIndexedAccessType(node as IndexedAccessTypeNode);
|
||||
case SyntaxKind.MappedType:
|
||||
|
||||
21
tests/baselines/reference/thisTag3.errors.txt
Normal file
21
tests/baselines/reference/thisTag3.errors.txt
Normal file
@ -0,0 +1,21 @@
|
||||
/a.js(7,9): error TS2730: An arrow function cannot have a 'this' parameter.
|
||||
/a.js(10,21): error TS2339: Property 'fn' does not exist on type 'C'.
|
||||
|
||||
|
||||
==== /a.js (2 errors) ====
|
||||
/**
|
||||
* @typedef {{fn(a: string): void}} T
|
||||
*/
|
||||
|
||||
class C {
|
||||
/**
|
||||
* @this {T}
|
||||
~~~~
|
||||
!!! error TS2730: An arrow function cannot have a 'this' parameter.
|
||||
* @param {string} a
|
||||
*/
|
||||
p = (a) => this.fn("" + a);
|
||||
~~
|
||||
!!! error TS2339: Property 'fn' does not exist on type 'C'.
|
||||
}
|
||||
|
||||
21
tests/baselines/reference/thisTag3.symbols
Normal file
21
tests/baselines/reference/thisTag3.symbols
Normal file
@ -0,0 +1,21 @@
|
||||
//// [tests/cases/conformance/jsdoc/thisTag3.ts] ////
|
||||
|
||||
=== /a.js ===
|
||||
/**
|
||||
* @typedef {{fn(a: string): void}} T
|
||||
*/
|
||||
|
||||
class C {
|
||||
>C : Symbol(C, Decl(a.js, 0, 0))
|
||||
|
||||
/**
|
||||
* @this {T}
|
||||
* @param {string} a
|
||||
*/
|
||||
p = (a) => this.fn("" + a);
|
||||
>p : Symbol(C.p, Decl(a.js, 4, 9))
|
||||
>a : Symbol(a, Decl(a.js, 9, 9))
|
||||
>this : Symbol(C, Decl(a.js, 0, 0))
|
||||
>a : Symbol(a, Decl(a.js, 9, 9))
|
||||
}
|
||||
|
||||
27
tests/baselines/reference/thisTag3.types
Normal file
27
tests/baselines/reference/thisTag3.types
Normal file
@ -0,0 +1,27 @@
|
||||
//// [tests/cases/conformance/jsdoc/thisTag3.ts] ////
|
||||
|
||||
=== /a.js ===
|
||||
/**
|
||||
* @typedef {{fn(a: string): void}} T
|
||||
*/
|
||||
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
/**
|
||||
* @this {T}
|
||||
* @param {string} a
|
||||
*/
|
||||
p = (a) => this.fn("" + a);
|
||||
>p : (this: T, a: string) => any
|
||||
>(a) => this.fn("" + a) : (this: T, a: string) => any
|
||||
>a : string
|
||||
>this.fn("" + a) : any
|
||||
>this.fn : any
|
||||
>this : this
|
||||
>fn : any
|
||||
>"" + a : string
|
||||
>"" : ""
|
||||
>a : string
|
||||
}
|
||||
|
||||
16
tests/cases/conformance/jsdoc/thisTag3.ts
Normal file
16
tests/cases/conformance/jsdoc/thisTag3.ts
Normal file
@ -0,0 +1,16 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @filename: /a.js
|
||||
|
||||
/**
|
||||
* @typedef {{fn(a: string): void}} T
|
||||
*/
|
||||
|
||||
class C {
|
||||
/**
|
||||
* @this {T}
|
||||
* @param {string} a
|
||||
*/
|
||||
p = (a) => this.fn("" + a);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user