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
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~.
Bug Report
Error happens only when:
...rest
🔎 Search Terms
type alias, named tuple, interface
🕗 Version & Regression Information
Typescript v4.9.3
⏯ Playground Link
Playground link with relevant code
💻 Code
The following code throws that error:
All of the following below works fine:
🙁 Actual behavior
TSC throws error:
🙂 Expected behavior
Successfull compilation
The text was updated successfully, but these errors were encountered: