Docs menu

E004: One of the values in your array's initializer list is the wrong type

What compiler error E004 means, and how to fix it.

An array holds one specific type of value – an int[3] holds three ints, a string[2] holds two strings, and so on. If even one value in the initializer list doesn’t match that type, Turf catches it right away instead of letting a mixed-up array sneak into your program.

Example
immut primes: int[3] = [2, 3, 5];   // correct -- every value is an int

If one of the values is the wrong type:

Example
immut primes: int[3] = [2, 3, "five"];   // "five" is a string, not an int

Turf tells you the element type the array holds and the type of the value it found, so you know what to look for when you scan the list for the odd one out.

To fix it, make sure every value in the list is really the array’s declared type. If you have a value of a different type that should logically become that type, convert it explicitly:

Example
immut primes: int[3] = [2, 3, 5];   // just use the right value directly

This is a great one to double-check whenever you’re typing out a long list of values by hand – it’s easy for one typo (like quoting a number by accident) to slip in.

Run turf --explain E004 in a terminal to read this again.

Last updated: Oct 15, 2026Edit this page on GitHub

Esc

Type to search.