Rewrite internal ast and whole type interface