Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5133,7 +5133,11 @@ func (c *Checker) checkInterfaceDeclaration(node *ast.Node) {
// run subsequent checks only if first set succeeded
if c.checkInheritedPropertiesAreIdentical(t, firstInterfaceDeclaration.Name()) {
for _, baseType := range c.getBaseTypes(t) {
c.checkTypeAssignableTo(typeWithThis, c.getTypeWithThisArgument(baseType, t.AsInterfaceType().thisType, false), firstInterfaceDeclaration.Name(), diagnostics.Interface_0_incorrectly_extends_interface_1)
message := diagnostics.Interface_0_incorrectly_extends_interface_1
if baseType.flags&TypeFlagsTypeParameter != 0 {
message = diagnostics.Interface_0_cannot_extend_type_parameter_1
}
c.checkTypeAssignableTo(typeWithThis, c.getTypeWithThisArgument(baseType, t.AsInterfaceType().thisType, false), firstInterfaceDeclaration.Name(), message)
}
c.checkIndexConstraints(t, symbol /*isStaticIndex*/, false)
}
Expand Down
1 change: 1 addition & 0 deletions tsc/internal/diagnostics/diagnosticMessages.generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@
"This_expression_is_never_nullish_2881": "This expression is never nullish.",
"Cannot_find_module_or_type_declarations_for_side_effect_import_of_0_2882": "Cannot find module or type declarations for side-effect import of '{0}'.",
"The_inferred_type_of_0_cannot_be_named_without_a_reference_to_2_from_1_This_is_likely_not_portable_A_2883": "The inferred type of '{0}' cannot be named without a reference to '{2}' from '{1}'. This is likely not portable. A type annotation is necessary.",
"Interface_0_cannot_extend_type_parameter_1_2884": "Interface '{0}' cannot extend type parameter '{1}'.",
"Import_declaration_0_is_using_private_name_1_4000": "Import declaration '{0}' is using private name '{1}'.",
"Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002": "Type parameter '{0}' of exported class has or is using private name '{1}'.",
"Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004": "Type parameter '{0}' of exported interface has or is using private name '{1}'.",
Expand Down
4 changes: 4 additions & 0 deletions tsc/internal/diagnostics/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4050,6 +4050,10 @@
"category": "Error",
"code": 2883
},
"Interface '{0}' cannot extend type parameter '{1}'.": {
"category": "Error",
"code": 2884
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
3 changes: 3 additions & 0 deletions tsc/internal/diagnostics/diagnostics_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
interfaceExtendsConstrainedTypeParameter.ts(1,11): error TS2884: Interface 'Constrained<T>' cannot extend type parameter 'T'.
'Constrained<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'.
interfaceExtendsConstrainedTypeParameter.ts(2,36): error TS2312: An interface can only extend an object type or intersection of object types with statically known members.
interfaceExtendsConstrainedTypeParameter.ts(5,11): error TS2430: Interface 'Derived' incorrectly extends interface 'Base'.
Types of property 'value' are incompatible.
Type 'string' is not assignable to type 'number'.


==== interfaceExtendsConstrainedTypeParameter.ts (3 errors) ====
interface Constrained<T extends object> extends T {}
~~~~~~~~~~~
!!! error TS2884: Interface 'Constrained<T>' cannot extend type parameter 'T'.
!!! error TS2884: 'Constrained<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'.
interface Unconstrained<T> extends T {}
~
!!! error TS2312: An interface can only extend an object type or intersection of object types with statically known members.

interface Base { value: number }
interface Derived extends Base { value: string }
~~~~~~~
!!! error TS2430: Interface 'Derived' incorrectly extends interface 'Base'.
!!! error TS2430: Types of property 'value' are incompatible.
!!! error TS2430: Type 'string' is not assignable to type 'number'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @noEmit: true
// @noTypesAndSymbols: true
interface Constrained<T extends object> extends T {}
interface Unconstrained<T> extends T {}

interface Base { value: number }
interface Derived extends Base { value: string }
Loading