-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add conditions to check for class extension or implementation of prim… #55712
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b4a4014
Add conditions to check for class extension or implementation of prim…
qwefgh90 f05f118
Fix incorrect error messages
qwefgh90 63c8122
fix incorrect error message and error numbers to match new error numb…
qwefgh90 3868ca4
remove check functions with duplicate structure
qwefgh90 8b29c30
Merge branch 'main' into derived-46246
sandersn 3795856
fix diagnosticMessages after merge+update baselines
sandersn 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
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/classImplementsPrimitive.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,17 @@ | ||
classImplementsPrimitive.ts(3,20): error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. | ||
classImplementsPrimitive.ts(4,21): error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. | ||
classImplementsPrimitive.ts(5,21): error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. | ||
|
||
|
||
==== classImplementsPrimitive.ts (3 errors) ==== | ||
// classes cannot implement primitives | ||
|
||
class C implements number { } | ||
~~~~~~ | ||
!!! error TS2864: A class cannot implement a primitive type like 'number'. It can only implement other named object types. | ||
class C2 implements string { } | ||
~~~~~~ | ||
!!! error TS2864: A class cannot implement a primitive type like 'string'. It can only implement other named object types. | ||
class C3 implements boolean { } | ||
~~~~~~~ | ||
!!! error TS2864: A class cannot implement a primitive type like 'boolean'. It can only implement other named object types. |
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,26 @@ | ||
//// [tests/cases/compiler/classImplementsPrimitive.ts] //// | ||
|
||
//// [classImplementsPrimitive.ts] | ||
// classes cannot implement primitives | ||
|
||
class C implements number { } | ||
class C2 implements string { } | ||
class C3 implements boolean { } | ||
|
||
//// [classImplementsPrimitive.js] | ||
// classes cannot implement primitives | ||
var C = /** @class */ (function () { | ||
function C() { | ||
} | ||
return C; | ||
}()); | ||
var C2 = /** @class */ (function () { | ||
function C2() { | ||
} | ||
return C2; | ||
}()); | ||
var C3 = /** @class */ (function () { | ||
function C3() { | ||
} | ||
return C3; | ||
}()); |
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/classImplementsPrimitive.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,14 @@ | ||
//// [tests/cases/compiler/classImplementsPrimitive.ts] //// | ||
|
||
=== classImplementsPrimitive.ts === | ||
// classes cannot implement primitives | ||
|
||
class C implements number { } | ||
>C : Symbol(C, Decl(classImplementsPrimitive.ts, 0, 0)) | ||
|
||
class C2 implements string { } | ||
>C2 : Symbol(C2, Decl(classImplementsPrimitive.ts, 2, 29)) | ||
|
||
class C3 implements boolean { } | ||
>C3 : Symbol(C3, Decl(classImplementsPrimitive.ts, 3, 30)) | ||
|
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,14 @@ | ||
//// [tests/cases/compiler/classImplementsPrimitive.ts] //// | ||
|
||
=== classImplementsPrimitive.ts === | ||
// classes cannot implement primitives | ||
|
||
class C implements number { } | ||
>C : C | ||
|
||
class C2 implements string { } | ||
>C2 : C2 | ||
|
||
class C3 implements boolean { } | ||
>C3 : C3 | ||
|
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/errorLocationForInterfaceExtension.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
errorLocationForInterfaceExtension.ts(3,21): error TS2840: An interface cannot extend a primitive type like 'string'; an interface can only extend named types and classes | ||
errorLocationForInterfaceExtension.ts(3,21): error TS2840: An interface cannot extend a primitive type like 'string'. It can only extend other named object types. | ||
|
||
|
||
==== errorLocationForInterfaceExtension.ts (1 errors) ==== | ||
var n = ''; | ||
|
||
interface x extends string { } | ||
~~~~~~ | ||
!!! error TS2840: An interface cannot extend a primitive type like 'string'; an interface can only extend named types and classes | ||
!!! error TS2840: An interface cannot extend a primitive type like 'string'. It can only extend other named object types. | ||
|
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
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 @@ | ||
// classes cannot implement primitives | ||
|
||
class C implements number { } | ||
class C2 implements string { } | ||
class C3 implements boolean { } |
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.