TL;DR: My function-backed Action that attempts to assign a GeoPoint to a Geohash property fails with an error that seems to say it was expecting a string.
I have an Object Type with a String property that has been set as a Geohash in the property editor. The field in the backing dataset contains strings representing lat,long pairs, formatted like '12.123456,34.345678'.
I then have a function-backed action to edit Objects of that Object type. It's currently set up to take a string as input (with the regex ^-?[0-8]?\d\.\d+,-?1?[0-7]?\d\.\d+$
used as Submission Criteria to ensure it matches the expected lat,long format). The Typescript function then assigns it to the Object Type as a GeoPoint like:
@Edits(myObjectType)
@OntologyEditFunction()
public editMyObjectType(
myObject: myObjectType,
.....
latlong?: string,
.....
): void (
.....
let geopoint = latlong? GeoPoint.fromString(latlong) : undefined;
.....
const cols: Partial<myObjectType> = {
.....
coordinate: geopoint
.....
}
Object.assign(myObject, cols);
}
This raises no errors. The tooltip when I hover on coordinate
in the cols
variable shows that, based on the imported Object Type of which it is an instance, it expects a value of type GeoPoint | undefined
. GeoPoint.fromString(latlong)
, where latlong
is a string, obviously stores a GeoPoint in geopoint
(when not undefined).
In the frontend, though, when I try to submit the Action I get this error:
Failed to apply change.
Error: [Actions] PropertyTypeDoesNotMatch
Error ID: <a UUID>
Related values:
- propertyTypeRid: Optional[ri.ontology.main.property.<another UUID>]
- expectedType: Optional[ValueType{value: PrimitiveWrapper{value: STRING}}]
- actualType: Optional[Value{value: GeohashWrapper{value: 12.123456,34.345678}}]
That value at the end, 12.123456,34.345678
, always matches whatever I put into the latlong field in question.
It appears as though the Object Type is expecting to receive a string from the function here, despite that in the Typescript editor it expects a GeoPoint and shows an error if I try to pass it a string. What gives?
Edit: Also the function appears to work fine when testing from the Live Preview in the Typescript editor, returning an Object with e.g. coordinate: 12.123456,34.345678
.
Edit 2: I see that a GeoPoint is not simply a lat,long string, but a struct containing a separate lat and long value. This only begs the question: in Typescript, why does it see the coordinate
property of myObject
as a GeoPoint in the first place? Why can I not assign it a string?
I got your code to run without issues on a simple object type with properties: id (string), name (string) and location (geohash). I don't think there's an error in your code, including with the type signatures. Things I would double check
In other words, I suspect the code is a red herring.