Fix #14916 with an additional validity check in deriveTyData