You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on the TypeScript type definitions of this library as stated here: #77
I noticed that some functions return either an object with the result or an object with an error string. For example swe_houses which you can find here:
As you can see the comments lie a bit in telling you that everything is in one object. But if you look at the code you see that you either get an object with the result details or an object with just an error string.
Now the typing of this return value would look like this:
After calling this method however one has to know which kind of object the result is. To make this check simpler I would like to propose the usage of discriminating unions in the result type.
This would mean that we could add a type: "ok" | "error" member to each object and make the usage of the library functions simpler. So the typing could look like this:
I'm currently working on the TypeScript type definitions of this library as stated here: #77
I noticed that some functions return either an object with the result or an object with an error string. For example
swe_houses
which you can find here:As you can see the comments lie a bit in telling you that everything is in one object. But if you look at the code you see that you either get an object with the result details or an object with just an error string.
Now the typing of this return value would look like this:
After calling this method however one has to know which kind of object the result is. To make this check simpler I would like to propose the usage of discriminating unions in the result type.
This would mean that we could add a
type: "ok" | "error"
member to each object and make the usage of the library functions simpler. So the typing could look like this:The calling code could then look like this (with correct type resolution in TypeScript):
I think this should be fairly simple and straight-forward to achieve.
The text was updated successfully, but these errors were encountered: