-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Describe the bug
Trying to expand any entity (e.g. opportunity) onto ownerid will result in an intersection type (SystemUser & Team) instead of a union type (SystemUser | Team). I doubt this is intentional, as SystemUser and Team do not overlap sufficiently.
To Reproduce
Steps to reproduce the behavior:
- Write an XrmQuery similar to this:
await XrmQuery
.retrieveMultiple(x => x.opportunities)
.select(x => [...]) // whichever select works
.expand(x => (x.ownerid), x => { // <- TS2345
if ("name" in x) {
return [x.name];
}
return [];
})
.promise();Expected behavior
Not a TS2345. I'd expect a Union type instead of an intersection type. Ownerid is either Team or SystemUser. Not both.
Screenshots
Environment
- CRM/D365/CDS version: 9.2.x
- Tool version: current
- Other applicable environments: Independent of environment.
Additional context
I have a proposed fix:
In CreateCommon.fs you can simply add a function aptly named "unionExpand":
let rec unionExpand isFirst (types: TsType list list) =
if types |> List.forall (fun x -> x.IsEmpty) then [] else
let current =
match isFirst with
| true -> types.Head.Head
| false -> TsType.Union (types |> List.map (fun x -> x.Head))
current :: unionExpand false (types |> List.map (fun x -> x.Tail))Which does the same thing as intersectExpand except it takes unions.
Replace Variable.Create(varName, TsType.SpecificGeneric(expandGrouping, intersectExpand true varTypes)) in "mergeOwnerExpand" with Variable.Create(varName, TsType.SpecificGeneric(expandGrouping, unionExpand true varTypes)).