bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Enhance `union(object...)` return type inference

Open jeskew opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. The union function today will perform a deep merge on objects, but the type system will cast the return type down to object unless every argument has a literal type. This causes errors that would be evident from manual inspection to pass unremarked by the type checker, such as:

// type: { a: 'a' }
var a = { a: 'a' }

// type: { b: 'b' }
var b = { b: 'b'}

// type: { a: 'a', b: 'b' }
var c = union(a, b)

// the compiler will catch this and raise a diagnostic
output c = c.c

param one { one: string }
param two { two: string }

// type: object
var three = union(one, two)

// no diagnostic, but this will cause a runtime error
output three = three.three

Describe the solution you'd like Even with non-literal types, union(object...) could perform some inference based on its arguments. This will be rather time consuming because union(object...) performs a deep merge.

jeskew avatar Feb 21 '24 19:02 jeskew