Rename internal id to index, add tests

As discussed with @artemp - the `type_id` is actually a reverse index of a given type in the variant. This is not designed to be a public api but makes sense to test. This changes the name for clarity and adds tests.

@artemp - look good?