Skip to content
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

Change type of $conf from SimpleObject to class to enable types properties #41

Open
BePo65 opened this issue Jan 9, 2025 · 2 comments

Comments

@BePo65
Copy link
Contributor

BePo65 commented Jan 9, 2025

Today the $conf property of EsDay is a Record<string, SimpleType. This enables e.g. plugins to add arbitrary properties to this object that can be used by the plugin.

If we changed the type of $conf to the instance of a class (to be created), a plugin can use module augmentation to add properties to $conf. This way the new properties do not have to be of union type SimpleType as today, but can be of a specific simple type (e.g. boolean). This would enable type checking by the typescript compiler.

Another positive effect would be that we get an automatic documentation of the configuration parameters of a plugin.

The used class should have a clone method to replace the destructuring command used with the current implementation.
This could be implemented like this (based on a github gist:

clone() {
  return Object.assign(
    Object.create(
      // Set the prototype of the new object to the prototype of the instance.
      // Used to allow new object behave like class instance.
      Object.getPrototypeOf(this)
    ),
    this
  )
}
@g-mero
Copy link
Owner

g-mero commented Jan 12, 2025

I will try this.

@BePo65
Copy link
Contributor Author

BePo65 commented Jan 14, 2025

Its only been today that I came across the arg_1 properties of $conf.

An idea to implement this in a conf class, we could perhaps be:

class conf {
  args: Record<string, SimpleType>
  clone() {
    :
  }
}

This way, we only had to replace e.g. args_1 with args.args_1 - but tht is just an idea 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants