You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Interface 'MyInterface<T>' incorrectly extends interface - for named tuple type that has '...rest' param #51751
typeMyType=[name1:string,name2: number,
...rest:any[]]interfaceMyInterfaceextendsMyType{//MyInterface is not generic => works}// ----------- OR -------------typeMyType=[// MyType does not have ...rest => works finename1:string,name2: number]interfaceMyInterface<T>extendsMyType{}// ------------ OR ------------typeMyType=[// MyType typle elements are not named => works finestring,number,
...any[]]interfaceMyInterface<T>extendsMyType{}
fwiw having an interface extend a tuple seems like an odd thing to do in the first place. If the interface has any properties or methods then I don’t think you can even construct a legal value (without type assertions, anyway).
fwiw having an interface extend a tuple seems like an odd thing to do
The main (maybe only?) reason to use interface vs type alias is ability to merge declarations. That constraint of type alias was an odd design decision, also even having types+interfaces vs just one of those that combines everything is weird and confusing
It probably wouldn't be that hard to fix but it would increase the complexity of the code a little bit.
It doesn't work because the interface checks if it's extending the base type correctly. To do that it checks if that resulting interface it's assignable to all of its bases. So it's checking if MyInterface<T> to [string, number, ...any[]]. The target is a tuple type but the source is not an array and it's not a tuple and since the target tuple is variable the propertiesRelatedTo determines that this source is not assignable to this target.
The case with MyInterface works OK because this type manages to get normalized during prior stages and it becomes equivalent to its base. Note that adding any properties to MyInterface prevents that and it also errors.
Cases without a variable element on that tuple likely work because the compiler is able to get past that "is tuple variable" check and actually gets to comparing object properties~.
Activity
RyanCavanaugh commentedon Dec 5, 2022
This is probably going to be extremely difficult to fix (or possibly trivial?). Weird stuff.
fatcerberus commentedon Dec 6, 2022
fwiw having an interface extend a tuple seems like an odd thing to do in the first place. If the interface has any properties or methods then I don’t think you can even construct a legal value (without type assertions, anyway).
pmunin commentedon Dec 7, 2022
The main (maybe only?) reason to use interface vs type alias is ability to merge declarations. That constraint of type alias was an odd design decision, also even having types+interfaces vs just one of those that combines everything is weird and confusing
Andarist commentedon Mar 24, 2023
It probably wouldn't be that hard to fix but it would increase the complexity of the code a little bit.
It doesn't work because the interface checks if it's extending the base type correctly. To do that it checks if that resulting interface it's assignable to all of its bases. So it's checking if
MyInterface<T>to[string, number, ...any[]]. The target is a tuple type but the source is not an array and it's not a tuple and since the target tuple is variable thepropertiesRelatedTodetermines that this source is not assignable to this target.The case with
MyInterfaceworks OK because this type manages to get normalized during prior stages and it becomes equivalent to its base. Note that adding any properties toMyInterfaceprevents that and it also errors.Cases without a variable element on that tuple likely work because the compiler is able to get past that "is tuple variable" check and actually gets to comparing object properties~.