Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance union(object...) return type inference #13401

Open
jeskew opened this issue Feb 21, 2024 · 0 comments
Open

Enhance union(object...) return type inference #13401

jeskew opened this issue Feb 21, 2024 · 0 comments
Labels
enhancement New feature or request type system

Comments

@jeskew
Copy link
Contributor

jeskew commented Feb 21, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request type system
Projects
Status: Todo
Development

No branches or pull requests

2 participants