Why this fires¶
An array literal is being checked against an expected element type — usually because it's assigned to a let/const with an explicit array type, or passed as an argument to a parameter typed [T] — and one of its elements doesn't match T.
let names: [str] = ["Ana", "Bo", 3]
// ^ error[TE008]: array element type mismatch: expected str, found intFix it¶
Make every element match the declared element type:
let names: [str] = ["Ana", "Bo", "Cid"] // okIf the array is genuinely meant to hold mixed types, drop the specific element type and use [any], or don't annotate the type at all and let the array's own inferred (possibly union) type stand.
See also¶
TE001— the generallet-binding type mismatch.- /docs/data-structures — arrays and their element types.