Confusing error message with incompatible readonly tuple types #35060
Labels
Bug
A bug in TypeScript
Domain: Error Messages
The issue relates to error messaging
Fixed
A PR has been merged for this issue
Good First Issue
Well scoped, documented and has the green light
Help Wanted
You can do this
Milestone
TypeScript Version: 3.8.0-dev.20191112
Search Terms: readonly, array, error, mutable, tuple,
Code
Expected behavior:
Errors saying that
readonly [0]
cannot be assigned toreadonly []
orreadonly [1]
due to incompatible lengths or element types.Actual behavior:
Contradictory error messages about absurdities like "the mutable type
readonly
[]
", suggesting that somereadonly
arrays are not, in fact,readonly
, and generally prompting developers to question their own sanity at a slightly greater rate than usual.It looks like #30916, the fix for #30839, went a bit too far in making the error messages for tuple mismatches human-friendly. If both the source and target types are assignable to
ReadonlyArray
, then the error message should probably not mention mutability at all and just say the types are incompatible. Further elaborations aboutlength
or index signature value mismatches should stay how they are now.Thanks to @eyelidlessness for noticing this.
Playground Link
Related Issues:
#30839: Poor error message elaborations for array-like types
#30916: Elaborate array and tuple relation errors
The text was updated successfully, but these errors were encountered: