Better type checking for factory methods.