-
Notifications
You must be signed in to change notification settings - Fork 3
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
Find better way to support empty constructor and constructor with arguments #67
Comments
I got the current solution from https://stackoverflow.com/questions/39407311/typescript-class-overload-signature-is-not-compatible-with-function-implementa |
I usually use static methods to overload:
|
@andreas-aeschlimann Thanks, I will try out factory methods after my holidays! |
Problem: The class generated by Knora defines an empty constructor because of Solution: Provide a
Furthermore, the consistency checks could be in a method that always look the same:
If we also need checks on specific properties, I suggest that we use getters and setters as follows:
The frontend has different needs as the backend and therefore should be able to easily extend these classes. For example, if we need stricter consistency checks or deeper checks in setters, we can still extend a class and implement this. In any case that we want to adjust a class on the client, we will need to extend it anyway. It makes no sense to implement too much TypeScript through Knora. |
So there would be no way to call the empty constructor directly, but only via the public static method. I think that's a good approach.
I like your idea. We would have to come up with a way to keep in sync with the Knora API. More properties could be added or their names could change. I have added I think the proper way to do this is coordinating the releases with @subotic and add automated e2e test with an actual Knora, see https://github.com/dasch-swiss/knora-api-js-lib-test/blob/angular/.travis.yml.
Yes, we should get all necessary information from Knora regarding the API's interface, but not more than that. |
Currently, complex values like
ReadDateValue
orReadGeomValue
are instantiated in two steps: first,json2typescript
creates an instance ofParseReadDateValue
orParseReadGeomValue
, respectively. From this, aReadDateValue
orReadGeomValue
is constructed. All classes are subclasses ofReadValue
and therefore we need to support two constructor signatures: an empty and a non-empty one:https://github.com/dhlab-basel/knora-api-js-lib/blob/4bbfa88e95e351662e2e3e171d625d8ae96bc338/src/models/v2/resources/values/read-value.ts#L42-L66
The solution was to make every parameter optional. But this is error prone, see #66.
The text was updated successfully, but these errors were encountered: