Type checking and flattening of indexed types