SkipLabs / skip

Skip is a framework for building reactive services
https://skiplabs.io
MIT License
152 stars 10 forks source link

Adds the constructor signature to the Resource interface. #407

Closed pikatchu closed 1 week ago

pikatchu commented 2 weeks ago

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.

skiplabsdaniel commented 2 weeks 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.

pikatchu commented 2 weeks ago

Ah ok. Thanks!

beauby commented 2 weeks ago

So should we make Resource a class instead of an interface?

mbouaziz commented 2 weeks ago

Or would that work?

export type Resource = {
  new (params: Record<string, string>): Resource;
...

Edit: answer: no

pikatchu commented 2 weeks ago

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?

pikatchu commented 1 week ago

Ok looks like what I am trying to do is just not possible in TS ...

jberdine commented 1 week ago

FMI, was the possibility of making Resource a class also not going to work?