-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix(31046): more accurate error message when derived class has different constructor signature #40073
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
fix(31046): more accurate error message when derived class has different constructor signature #40073
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/assignmentCompatability44.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
tests/cases/compiler/assignmentCompatability44.ts(5,7): error TS2322: Type 'typeof Foo' is not assignable to type 'new () => Foo'. | ||
Types of construct signatures are incompatible. | ||
Type 'new (x: number) => Foo' is not assignable to type 'new () => Foo'. | ||
|
||
|
||
==== tests/cases/compiler/assignmentCompatability44.ts (1 errors) ==== | ||
class Foo { | ||
constructor(x: number) {} | ||
} | ||
|
||
const foo: { new(): Foo } = Foo; | ||
~~~ | ||
!!! error TS2322: Type 'typeof Foo' is not assignable to type 'new () => Foo'. | ||
a-tarasyuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
!!! error TS2322: Types of construct signatures are incompatible. | ||
!!! error TS2322: Type 'new (x: number) => Foo' is not assignable to type 'new () => Foo'. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//// [assignmentCompatability44.ts] | ||
class Foo { | ||
constructor(x: number) {} | ||
} | ||
|
||
const foo: { new(): Foo } = Foo; | ||
|
||
|
||
//// [assignmentCompatability44.js] | ||
var Foo = /** @class */ (function () { | ||
function Foo(x) { | ||
} | ||
return Foo; | ||
}()); | ||
var foo = Foo; |
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/assignmentCompatability44.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
=== tests/cases/compiler/assignmentCompatability44.ts === | ||
class Foo { | ||
>Foo : Symbol(Foo, Decl(assignmentCompatability44.ts, 0, 0)) | ||
|
||
constructor(x: number) {} | ||
>x : Symbol(x, Decl(assignmentCompatability44.ts, 1, 16)) | ||
} | ||
|
||
const foo: { new(): Foo } = Foo; | ||
>foo : Symbol(foo, Decl(assignmentCompatability44.ts, 4, 5)) | ||
>Foo : Symbol(Foo, Decl(assignmentCompatability44.ts, 0, 0)) | ||
>Foo : Symbol(Foo, Decl(assignmentCompatability44.ts, 0, 0)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
=== tests/cases/compiler/assignmentCompatability44.ts === | ||
class Foo { | ||
>Foo : Foo | ||
|
||
constructor(x: number) {} | ||
>x : number | ||
} | ||
|
||
const foo: { new(): Foo } = Foo; | ||
>foo : new () => Foo | ||
>Foo : typeof Foo | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/assignmentCompatability45.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tests/cases/compiler/assignmentCompatability45.ts(7,7): error TS2322: Type 'typeof B' is not assignable to type 'typeof A'. | ||
Types of construct signatures are incompatible. | ||
Type 'new (x: number) => B' is not assignable to type 'new () => A'. | ||
|
||
|
||
==== tests/cases/compiler/assignmentCompatability45.ts (1 errors) ==== | ||
abstract class A {} | ||
class B extends A { | ||
constructor(x: number) { | ||
super(); | ||
} | ||
} | ||
const b: typeof A = B; | ||
~ | ||
!!! error TS2322: Type 'typeof B' is not assignable to type 'typeof A'. | ||
!!! error TS2322: Types of construct signatures are incompatible. | ||
!!! error TS2322: Type 'new (x: number) => B' is not assignable to type 'new () => A'. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//// [assignmentCompatability45.ts] | ||
abstract class A {} | ||
class B extends A { | ||
constructor(x: number) { | ||
super(); | ||
} | ||
} | ||
const b: typeof A = B; | ||
|
||
|
||
//// [assignmentCompatability45.js] | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var A = /** @class */ (function () { | ||
function A() { | ||
} | ||
return A; | ||
}()); | ||
var B = /** @class */ (function (_super) { | ||
__extends(B, _super); | ||
function B(x) { | ||
return _super.call(this) || this; | ||
} | ||
return B; | ||
}(A)); | ||
var b = B; |
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/assignmentCompatability45.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
=== tests/cases/compiler/assignmentCompatability45.ts === | ||
abstract class A {} | ||
>A : Symbol(A, Decl(assignmentCompatability45.ts, 0, 0)) | ||
|
||
class B extends A { | ||
>B : Symbol(B, Decl(assignmentCompatability45.ts, 0, 19)) | ||
>A : Symbol(A, Decl(assignmentCompatability45.ts, 0, 0)) | ||
|
||
constructor(x: number) { | ||
>x : Symbol(x, Decl(assignmentCompatability45.ts, 2, 16)) | ||
|
||
super(); | ||
>super : Symbol(A, Decl(assignmentCompatability45.ts, 0, 0)) | ||
} | ||
} | ||
const b: typeof A = B; | ||
>b : Symbol(b, Decl(assignmentCompatability45.ts, 6, 5)) | ||
>A : Symbol(A, Decl(assignmentCompatability45.ts, 0, 0)) | ||
>B : Symbol(B, Decl(assignmentCompatability45.ts, 0, 19)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
=== tests/cases/compiler/assignmentCompatability45.ts === | ||
abstract class A {} | ||
>A : A | ||
|
||
class B extends A { | ||
>B : B | ||
>A : A | ||
|
||
constructor(x: number) { | ||
>x : number | ||
|
||
super(); | ||
>super() : void | ||
>super : typeof A | ||
} | ||
} | ||
const b: typeof A = B; | ||
>b : typeof A | ||
>A : typeof A | ||
>B : typeof B | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Foo { | ||
constructor(x: number) {} | ||
} | ||
|
||
const foo: { new(): Foo } = Foo; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
abstract class A {} | ||
class B extends A { | ||
constructor(x: number) { | ||
super(); | ||
} | ||
} | ||
const b: typeof A = B; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.