Writes value at index. Never called with an out-of-range index. The implementation checks the type of value and converts it if it has to.