Closed pikatchu closed 1 week ago
A constructor signature cannot be added to an interface in TypeScript. If you implements It, it requires a the definition of ["contructor"] = (parameter ) => {..} We can force to manage (think about) parameters with an abstract class.
Ah ok. Thanks!
So should we make Resource
a class
instead of an interface
?
Or would that work?
export type Resource = {
new (params: Record<string, string>): Resource;
...
Edit: answer: no
So apparently there is no way to
Or would that work?
export type Resource = { new (params: Record<string, string>): Resource; ...
Edit: answer: no
Can you elaborate? I was about to try this too. Why doesn't it work?
Ok looks like what I am trying to do is just not possible in TS ...
FMI, was the possibility of making Resource
a class
also not going to work?
This doesn't change anything at runtime, but helps with discoverability. When somebody is trying to define a resource, what will happen is that they will sometimes need parameters. So for example, if we hit the endpoint: http://myapi.foo.com/myresource?name=julien. In this example, we are defining the resource myresource and we have { "name": "julien" } as a arguments.
The arguments are passed to us through the constructor. But since the constructor signature was not part of the interface, it was hard to discover ... This diff fixes that.