You need to call .Resolve on PredefinedTypes, or TypeSpec may end up being null.

ec.Module.PredefinedTypes.AsUndefined.TypeSpec => ec.Module.PredefinedTypes.AsUndefined.Resolve()