OK, got it now.
The variable declaration is correct, the value assignment is also syntactically correct. Unfortunately, the term assigned to the variable is of the wrong type. I think that such programming errors usually only become apparent during the program run. It is interesting that the compiler can also be tricked in this way.
It won't be easy to detect this programming error within the IDE. It happens quite often, for example, that a variable is read from an SQL cell that has not yet been filled, or that a loop is interrupted with an ‘out of bounds’ because not enough values are available (in a string, for example).
I can only think of a German programming saying,
which you should not take personally under any circumstances.
The saying goes:
IDIOTS ARE INVENTIVE, YOU JUST CAN'T PREDICT EVERYTHING.
At least the error message during the program execution then describes quite accurately what went wrong.