Closed as not planned
Description
π Search Terms
tuple type infer inference inheritance
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about tuples and type inference.
β― Playground Link
π» Code
declare type StringFirstTuple = [string, ...any];
class Foo {
spec(): StringFirstTuple {
return ["hello"]
}
}
class Bar extends Foo {
spec() {
return ["goodbye", {something: "else"}]
}
}
π Actual behavior
The spec
method on Bar
failed to typecheck, despite unambiguously implementing the same type signature as spec
on Foo
.
Annotating Bar
's spec
method to return a StringFirstTuple
typechecks properly.
The error message seems to indicate that the return type of spec
in Bar
has been generalized to Array<string | {something: string}>
before checking the overridden type.
π Expected behavior
A function that returns an array that is hard-coded to match a tuple type should be substitutable for a function that is specified to return that tuple type.
Additional information about the issue
No response