Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

TypeScript: improve ComponentConstructor type #242

Open
DavidPeicho opened this issue Aug 6, 2020 · 0 comments
Open

TypeScript: improve ComponentConstructor type #242

DavidPeicho opened this issue Aug 6, 2020 · 0 comments
Labels

Comments

@DavidPeicho
Copy link
Contributor

Hi,

Right now, component constructor accepts only objects containing the same attributes as the component, and false to use schema or not:

export interface ComponentConstructor<C extends Component<any>> {
  schema: ComponentSchema;
  isComponent: true;
  new (props?: Partial<Omit<C, keyof Component<any>>> | false): C;
}

The problem is that the systems accept only the default ComponentConstructor here. When creating custom component that doesn't need any schema, the developer ends up stuck with a constructor like:

export class FrameComponent extends Component<FramingParameters> {

  public target: Nullable<Target>;

  public constructor(target?: Target) {
    super(target);
    this.target = target ?? null;
  }
  ...
}

Which would work only if:

  1. The props argument contains attributes of the class ({ target: ... } in this case)
  2. The props argument can be false

Fix

1. Make the system class accept more generic component constructor

2. Re-think the instantiation / reset of component

  1. Regarding the constructor accepting false as props, wouldn't it make more sense to completely disable the schema check using a static argument? I am not sure what would be the use case of disabling the props schema per instance.

  2. Would it be possible to allow to forward properties that aren't of this type?

Let me know what you think! Thanks

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

No branches or pull requests

2 participants