mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(50952): Can't infer from this type on static class method call in JS Doc (#51149)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
co-authored by
Nathan Shively-Sanders
parent
60edd0685f
commit
42530c3c8d
@@ -14313,6 +14313,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
if (isInJSFile(declaration)) {
|
||||
const thisTag = getJSDocThisTag(declaration);
|
||||
if (thisTag && thisTag.typeExpression) {
|
||||
thisParameter = createSymbolWithType(createSymbol(SymbolFlags.FunctionScopedVariable, InternalSymbolName.This), getTypeFromTypeNode(thisTag.typeExpression));
|
||||
}
|
||||
}
|
||||
|
||||
const classType = declaration.kind === SyntaxKind.Constructor ?
|
||||
getDeclaredTypeOfClassOrInterface(getMergedSymbol((declaration.parent as ClassDeclaration).symbol))
|
||||
: undefined;
|
||||
|
||||
@@ -9,10 +9,10 @@ function C() {
|
||||
|
||||
this.e = this.m + 1
|
||||
>this.e : Symbol(e, Decl(classthisboth.js, 2, 11))
|
||||
>this : Symbol(__type, Decl(classthisboth.js, 2, 10))
|
||||
>this : Symbol(this)
|
||||
>e : Symbol(C.e, Decl(classthisboth.js, 5, 14))
|
||||
>this.m : Symbol(m, Decl(classthisboth.js, 2, 22))
|
||||
>this : Symbol(__type, Decl(classthisboth.js, 2, 10))
|
||||
>this : Symbol(this)
|
||||
>m : Symbol(m, Decl(classthisboth.js, 2, 22))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
=== /a.js ===
|
||||
export class C {
|
||||
>C : Symbol(C, Decl(a.js, 0, 0))
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @this {T}
|
||||
* @return {T}
|
||||
*/
|
||||
static a() {
|
||||
>a : Symbol(C.a, Decl(a.js, 0, 16))
|
||||
|
||||
return this;
|
||||
>this : Symbol(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @this {T}
|
||||
* @return {T}
|
||||
*/
|
||||
b() {
|
||||
>b : Symbol(C.b, Decl(a.js, 8, 5))
|
||||
|
||||
return this;
|
||||
>this : Symbol(this)
|
||||
}
|
||||
}
|
||||
|
||||
const a = C.a();
|
||||
>a : Symbol(a, Decl(a.js, 20, 5))
|
||||
>C.a : Symbol(C.a, Decl(a.js, 0, 16))
|
||||
>C : Symbol(C, Decl(a.js, 0, 0))
|
||||
>a : Symbol(C.a, Decl(a.js, 0, 16))
|
||||
|
||||
a; // typeof C
|
||||
>a : Symbol(a, Decl(a.js, 20, 5))
|
||||
|
||||
const c = new C();
|
||||
>c : Symbol(c, Decl(a.js, 23, 5))
|
||||
>C : Symbol(C, Decl(a.js, 0, 0))
|
||||
|
||||
const b = c.b();
|
||||
>b : Symbol(b, Decl(a.js, 24, 5))
|
||||
>c.b : Symbol(C.b, Decl(a.js, 8, 5))
|
||||
>c : Symbol(c, Decl(a.js, 23, 5))
|
||||
>b : Symbol(C.b, Decl(a.js, 8, 5))
|
||||
|
||||
b; // C
|
||||
>b : Symbol(b, Decl(a.js, 24, 5))
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
=== /a.js ===
|
||||
export class C {
|
||||
>C : C
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @this {T}
|
||||
* @return {T}
|
||||
*/
|
||||
static a() {
|
||||
>a : <T>(this: T) => T
|
||||
|
||||
return this;
|
||||
>this : T
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @this {T}
|
||||
* @return {T}
|
||||
*/
|
||||
b() {
|
||||
>b : <T>(this: T) => T
|
||||
|
||||
return this;
|
||||
>this : T
|
||||
}
|
||||
}
|
||||
|
||||
const a = C.a();
|
||||
>a : typeof C
|
||||
>C.a() : typeof C
|
||||
>C.a : <T>(this: T) => T
|
||||
>C : typeof C
|
||||
>a : <T>(this: T) => T
|
||||
|
||||
a; // typeof C
|
||||
>a : typeof C
|
||||
|
||||
const c = new C();
|
||||
>c : C
|
||||
>new C() : C
|
||||
>C : typeof C
|
||||
|
||||
const b = c.b();
|
||||
>b : C
|
||||
>c.b() : C
|
||||
>c.b : <T>(this: T) => T
|
||||
>c : C
|
||||
>b : <T>(this: T) => T
|
||||
|
||||
b; // C
|
||||
>b : C
|
||||
|
||||
@@ -9,7 +9,7 @@ function f(s) {
|
||||
|
||||
return this.n + s.length
|
||||
>this.n : Symbol(n, Decl(a.js, 0, 12))
|
||||
>this : Symbol(__type, Decl(a.js, 0, 11))
|
||||
>this : Symbol(this)
|
||||
>n : Symbol(n, Decl(a.js, 0, 12))
|
||||
>s.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(a.js, 4, 11))
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// @noEmit: true
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @filename: /a.js
|
||||
|
||||
export class C {
|
||||
/**
|
||||
* @template T
|
||||
* @this {T}
|
||||
* @return {T}
|
||||
*/
|
||||
static a() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @this {T}
|
||||
* @return {T}
|
||||
*/
|
||||
b() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
const a = C.a();
|
||||
a; // typeof C
|
||||
|
||||
const c = new C();
|
||||
const b = c.b();
|
||||
b; // C
|
||||
Reference in New Issue
Block a user