Skip to content

Commit c797f3b

Browse files
committed
Fix empty-targets lookup name var; fail-fast on empty Union/Intersection
Restore handling for lookups whose metadata returns an empty Targets array (e.g. owningbusinessunit in some Dataverse environments). The refactor in febde1c dropped the explicit Some [||] -> None guard, causing getLookupNameVars to render TsType.Union [] as the empty string and emit broken TypeScript. Type as string when targets are empty. Also guard TsStringUtil so empty Union/Intersection lists fail at generation time instead of producing invalid output silently.
1 parent febde1c commit c797f3b

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/CreateTypeScript/CreateWebEntities.fs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,18 @@ let getLookupNameVars (attrs: XrmAttribute list) =
225225
attrs
226226
|> List.filter (fun a -> a.specialType = SpecialType.EntityReference)
227227
|> List.map (fun a ->
228-
let unionType =
229-
a.targetEntitySets
230-
|> Array.map (fun e -> TsType.Custom $"\"{e.LogicalName}\"")
231-
|> Array.toList
232-
|> TsType.Union
228+
let vType =
229+
match a.targetEntitySets with
230+
| [||] -> TsType.String
231+
| tes ->
232+
tes
233+
|> Array.map (fun e -> TsType.Custom $"\"{e.LogicalName}\"")
234+
|> Array.toList
235+
|> TsType.Union
233236

234237
Variable.Create(
235238
$"\"{valueInfix a.logicalName}@Microsoft.Dynamics.CRM.lookuplogicalname\"",
236-
unionType,
239+
vType,
237240
Comment.Attribute(a.displayName, tes = a.targetEntitySets),
238241
optional = true
239242
))

src/TypeScript/TsStringUtil.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ and typeToString = function
3030
| TsType.Generic(n, t) -> sprintf "%s<%s>" n t
3131
| TsType.SpecificGeneric(n,ts)
3232
-> sprintf "%s<%s>" n (ts |> Seq.map typeToString |> String.concat ", ")
33+
| TsType.Union [] -> failwith "TsType.Union requires at least one type"
34+
| TsType.Intersection [] -> failwith "TsType.Intersection requires at least one type"
3335
| TsType.Union types -> types |> List.map wrapIfRecursive |> String.concat " | "
3436
| TsType.Intersection types -> types |> List.map wrapIfRecursive |> String.concat " & "
3537

0 commit comments

Comments
 (0)