-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Improve @overload
's interactions with constructors
#52577
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
tests/cases/conformance/jsdoc/overloadTag2.js(25,20): error TS7006: Parameter 'b' implicitly has an 'any' type. | ||
tests/cases/conformance/jsdoc/overloadTag2.js(30,9): error TS2554: Expected 1-2 arguments, but got 0. | ||
|
||
|
||
==== tests/cases/conformance/jsdoc/overloadTag2.js (2 errors) ==== | ||
export class Foo { | ||
#a = true ? 1 : "1" | ||
#b | ||
|
||
/** | ||
* Should not have an implicit any error, because constructor's return type is always implicit | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
* @param {number} b | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {number} a | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
*//** | ||
* @constructor | ||
* @param {number | string} a | ||
*/ | ||
constructor(a, b) { | ||
~ | ||
!!! error TS7006: Parameter 'b' implicitly has an 'any' type. | ||
this.#a = a | ||
this.#b = b | ||
} | ||
} | ||
var a = new Foo() | ||
~~~~~~~~~ | ||
!!! error TS2554: Expected 1-2 arguments, but got 0. | ||
!!! related TS6210 tests/cases/conformance/jsdoc/overloadTag2.js:15:8: An argument for 'a' was not provided. | ||
var b = new Foo('str') | ||
var c = new Foo(2) | ||
var d = new Foo('str', 2) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//// [overloadTag2.js] | ||
export class Foo { | ||
#a = true ? 1 : "1" | ||
#b | ||
|
||
/** | ||
* Should not have an implicit any error, because constructor's return type is always implicit | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
* @param {number} b | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {number} a | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
*//** | ||
* @constructor | ||
* @param {number | string} a | ||
*/ | ||
constructor(a, b) { | ||
this.#a = a | ||
this.#b = b | ||
} | ||
} | ||
var a = new Foo() | ||
var b = new Foo('str') | ||
var c = new Foo(2) | ||
var d = new Foo('str', 2) | ||
|
||
|
||
//// [overloadTag2.js] | ||
export class Foo { | ||
#a = true ? 1 : "1"; | ||
#b; | ||
/** | ||
* Should not have an implicit any error, because constructor's return type is always implicit | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
* @param {number} b | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {number} a | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
*/ /** | ||
* @constructor | ||
* @param {number | string} a | ||
*/ | ||
constructor(a, b) { | ||
this.#a = a; | ||
this.#b = b; | ||
} | ||
} | ||
var a = new Foo(); | ||
var b = new Foo('str'); | ||
var c = new Foo(2); | ||
var d = new Foo('str', 2); | ||
|
||
|
||
//// [overloadTag2.d.ts] | ||
export class Foo { | ||
constructor(a: string, b: number); | ||
constructor(a: number); | ||
constructor(a: string); | ||
#private; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
=== tests/cases/conformance/jsdoc/overloadTag2.js === | ||
export class Foo { | ||
>Foo : Symbol(Foo, Decl(overloadTag2.js, 0, 0)) | ||
|
||
#a = true ? 1 : "1" | ||
>#a : Symbol(Foo.#a, Decl(overloadTag2.js, 0, 18)) | ||
|
||
#b | ||
>#b : Symbol(Foo.#b, Decl(overloadTag2.js, 1, 23)) | ||
|
||
/** | ||
* Should not have an implicit any error, because constructor's return type is always implicit | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
* @param {number} b | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {number} a | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
*//** | ||
* @constructor | ||
* @param {number | string} a | ||
*/ | ||
constructor(a, b) { | ||
>a : Symbol(a, Decl(overloadTag2.js, 24, 16)) | ||
>b : Symbol(b, Decl(overloadTag2.js, 24, 18)) | ||
|
||
this.#a = a | ||
>this.#a : Symbol(Foo.#a, Decl(overloadTag2.js, 0, 18)) | ||
>this : Symbol(Foo, Decl(overloadTag2.js, 0, 0)) | ||
>a : Symbol(a, Decl(overloadTag2.js, 24, 16)) | ||
|
||
this.#b = b | ||
>this.#b : Symbol(Foo.#b, Decl(overloadTag2.js, 1, 23)) | ||
>this : Symbol(Foo, Decl(overloadTag2.js, 0, 0)) | ||
>b : Symbol(b, Decl(overloadTag2.js, 24, 18)) | ||
} | ||
} | ||
var a = new Foo() | ||
>a : Symbol(a, Decl(overloadTag2.js, 29, 3)) | ||
>Foo : Symbol(Foo, Decl(overloadTag2.js, 0, 0)) | ||
|
||
var b = new Foo('str') | ||
>b : Symbol(b, Decl(overloadTag2.js, 30, 3)) | ||
>Foo : Symbol(Foo, Decl(overloadTag2.js, 0, 0)) | ||
|
||
var c = new Foo(2) | ||
>c : Symbol(c, Decl(overloadTag2.js, 31, 3)) | ||
>Foo : Symbol(Foo, Decl(overloadTag2.js, 0, 0)) | ||
|
||
var d = new Foo('str', 2) | ||
>d : Symbol(d, Decl(overloadTag2.js, 32, 3)) | ||
>Foo : Symbol(Foo, Decl(overloadTag2.js, 0, 0)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
=== tests/cases/conformance/jsdoc/overloadTag2.js === | ||
export class Foo { | ||
>Foo : Foo | ||
|
||
#a = true ? 1 : "1" | ||
>#a : string | number | ||
>true ? 1 : "1" : 1 | "1" | ||
>true : true | ||
>1 : 1 | ||
>"1" : "1" | ||
|
||
#b | ||
>#b : any | ||
|
||
/** | ||
* Should not have an implicit any error, because constructor's return type is always implicit | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
* @param {number} b | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {number} a | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
*//** | ||
* @constructor | ||
* @param {number | string} a | ||
*/ | ||
constructor(a, b) { | ||
>a : string | number | ||
>b : any | ||
|
||
this.#a = a | ||
>this.#a = a : string | number | ||
>this.#a : string | number | ||
>this : this | ||
>a : string | number | ||
|
||
this.#b = b | ||
>this.#b = b : any | ||
>this.#b : any | ||
>this : this | ||
>b : any | ||
} | ||
} | ||
var a = new Foo() | ||
>a : Foo | ||
>new Foo() : Foo | ||
>Foo : typeof Foo | ||
|
||
var b = new Foo('str') | ||
>b : Foo | ||
>new Foo('str') : Foo | ||
>Foo : typeof Foo | ||
>'str' : "str" | ||
|
||
var c = new Foo(2) | ||
>c : Foo | ||
>new Foo(2) : Foo | ||
>Foo : typeof Foo | ||
>2 : 2 | ||
|
||
var d = new Foo('str', 2) | ||
>d : Foo | ||
>new Foo('str', 2) : Foo | ||
>Foo : typeof Foo | ||
>'str' : "str" | ||
>2 : 2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @checkJs: true | ||
// @allowJs: true | ||
// @target: esnext | ||
// @outdir: foo | ||
// @declaration: true | ||
// @filename: overloadTag2.js | ||
// @strict: true | ||
export class Foo { | ||
#a = true ? 1 : "1" | ||
#b | ||
|
||
/** | ||
* Should not have an implicit any error, because constructor's return type is always implicit | ||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
* @param {number} b | ||
*/ | ||
/** | ||
* @constructor | ||
* @overload | ||
* @param {number} a | ||
*/ | ||
/** | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test need to be written in such a way as to satisfy #52474? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean putting all the tags into a single comment? No, this test showed that that requirement isn't feasible; the parser can't distinguish between the end of a return-less There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, so #52474 is no longer a thing, okay. |
||
* @constructor | ||
* @overload | ||
* @param {string} a | ||
*//** | ||
* @constructor | ||
* @param {number | string} a | ||
*/ | ||
constructor(a, b) { | ||
this.#a = a | ||
this.#b = b | ||
} | ||
} | ||
var a = new Foo() | ||
var b = new Foo('str') | ||
var c = new Foo(2) | ||
var d = new Foo('str', 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
isJSDocConstructSignature
supposed to do the check?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusingly, JSDocConstructSignature refers to closure type syntax:
function(new: SomeClass)
is equivalent to TSnew (): SomeClass
.The naming scheme could be better though.