-
Notifications
You must be signed in to change notification settings - Fork 11
Model class attributes do not read from props, even when the property is present #42
Comments
Here is a response that fails to initialize the object attributes: {
"id" : "lab2_q1a",
"name" : "Question 1A",
"modelId" : "<redacted>",
"collectionNumber" : null,
"_links" : {
"self" : {
"href" : "<redacted>/api/fossils/lab2_q1a"
},
"fossil" : {
"href" : "<redacted>/api/fossils/lab2_q1a"
},
"taxa" : {
"href" : "<redacted>/api/fossils/lab2_q1a/taxa"
},
"rockUnit" : {
"href" : "<redacted>/api/fossils/lab2_q1a/rockUnit"
}
}
} This is my model class: import {HalProperty, HalResource} from "hal-rest-client";
class FossilModel extends HalResource {
@HalProperty("id")
id!: string;
@HalProperty()
name!: string;
@HalProperty()
modelId!: string;
@HalProperty()
collectionNumber: string | undefined
}
export default FossilModel; And this is the call to my API: client.fetch("/fossils/lab2_q1a", FossilModel)
.then(value => {
this.setState({fossils: [value]});
// Here, value.id === undefined even though it's in the response!
}); |
I traced the
It seems like the |
It looks like this is the issue: https://romkevandermeulen.nl/2018/01/24/typescript-property-decorators.html In short, the decorators only have access to the prototype of the class and therefore cannot reference |
I can not reproduce it on unit test. |
@deblockt Here's a sample! Repository Just clone it and run |
After using
then
on the promise from afetch
with my model class, the returned object's attributes are undefined. Theprops
attribute has all of the correct information, but it doesn't get applied to the model object like it stated in the readme:The text was updated successfully, but these errors were encountered: