It's 2020 and MSSQL still can't cast or convert from/to user-defined types
Come on, Microsoft - this should be as simple as using the metadata from sys.types. Look, even I can do it:
declare @SystemTypeId tinyint,
select @SystemTypeId = systemtypeid, @MaxLength = max_length from sys.types where name = 'TenantId';
--select * from sys.types;
declare @TypeName sysname = (select name from sys.types where systemtypeid = @SystemTypeId and usertypeid = @SystemTypeId and isuserdefined = 0 and istabletype = 0);
declare @TypeFullName sysname = @TypeName + (case
when @SystemTypeId in (167, 175) then '(' + cast(@MaxLength as varchar) + ')'
when @SystemTypeId in (239, 231) then '(' + cast((@MaxLength / 2) as varchar) + ')'
exec('select cast(somethingtobe_cast as ' + @TypeFullName + ');');
The above is ugly and hacky and obviously sub-optimal but I'm sure you guys have the smarts to make it better. So please, apply those smarts.