-
Notifications
You must be signed in to change notification settings - Fork 6
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
Allow type casting to like-Object definitions #24
Comments
I can think of another way to get this working w/ a union type. Would this alleviate the pain point you're experiencing?
Or you could overload
|
If I am using a custom utility module from shared resource that provides me many functions to handle I think those approaches will work if you have control over all types or they are known in advance. |
Have you tried removing the "closed object" syntax? -type Person = {| firstName: String, lastName: String |}
+type Person = { firstName: String, lastName: String }
fun getName(p:Person): String = "$(p.firstName) $(p.lastName)" It should work for your use case.. In most cases, DataWeave have structural types. That means it won't pay attention to the name of the type but yes to the structure of the type. In this specific case, by using |
Consider an Object received in an API looks like Following and can be represented as an instance of
Employee
type -In inheritance world, it is possible to have a structure like
Employee extends Person
.Consider following dataweave script -
This script fails with following error -
Person
is represented as a closed subset of anEmployee
.An explicit coercion of Employee to Person
getName(empExample as Person)
fails with following example -There are two ways to get this working -
getName({firstName: empExample.firstName, lastName: empExample.lastName})
.Person
to be an open object -type Person = {firstName: String, lastName: String}
, in which casegetName(empExample)
works.Will it make sense to allow type casting objects into other if they are closed subsets -
getName(empExample as Person)
?The text was updated successfully, but these errors were encountered: