dothtml-interfaces 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dothtml-interfaces",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Dependency injection interfaces for DOTHtml.",
5
5
  "main": "src/index.d.ts",
6
6
  "types": "src/index.d.ts",
@@ -26,22 +26,18 @@ export interface FrameworkItems {
26
26
  // html: IDotGenericElement;
27
27
  }
28
28
 
29
- export type ComponentArgs<TProps extends Array<string>, TEvents extends Array<string>> = {
30
- [key in TProps[number]]: any;
31
- } & {
32
- [key in TEvents[number]]: (...args: any[]) => void;
33
- }
34
-
35
29
 
36
30
  // TODO: there's a weird problem where if a constructor is not provided, it's not possible have a custom builder.
37
31
  // It should be the contsructor that depends on the builder, not the other way around. If we can't get this working,
38
32
  // it might just be better to rethink how stuff gets passed into components.
39
- export default interface IComponent<TProps extends Array<string> = [], TEvents extends Array<string> = []> {
33
+ export default interface IComponent/*<TProps extends Array<string> = [], TEvents extends Array<string> = []>*/ {
40
34
 
41
35
  readonly _?: FrameworkItems;
42
36
 
43
- new (attrs?: ComponentArgs<TProps, TEvents>): IComponent<TProps, TEvents>;
44
- new (): IComponent<TProps, TEvents>;
37
+ // Regrettably, TS forces clients to implement the constructor, which is not ideal because we want to internalize that.
38
+ // There's no way to make the constructor optional.
39
+ // new (attrs?: ComponentArgs<TProps, TEvents>): IComponent<TProps, TEvents>;
40
+ // new (): IComponent<TProps, TEvents>;
45
41
 
46
42
  // Lifecycle hooks
47
43
 
package/src/i-dot.d.ts CHANGED
@@ -335,16 +335,27 @@ export interface IDotDocument {
335
335
  }
336
336
 
337
337
  type Styles = string | IDotcssProp;
338
- interface IComponentFactory {
339
- <TProps extends Array<string>, TEvents extends Array<string>, T extends IComponent<TProps, TEvents>>(
340
- Base: new () => T, styles?: Styles | Styles[]
341
- ): new () => T;
342
- useStyles<T extends IComponent>(styles: Styles | Styles[]): (Base: new () => T) => new () => T;
343
- }
338
+ // interface IComponentFactory {
339
+ // <TProps extends string[], TEvents extends string[], T extends IComponent<TProps, TEvents>>(
340
+ // Base: new () => T, styles?: Styles | Styles[]
341
+ // ): new (attrs?: ComponentArgs<TProps, TEvents>) => T & { new (attrs?: ComponentArgs<TProps, TEvents>): IComponent<TProps, TEvents> };
342
+ // }
343
+
344
+ // interface IComponentFactory {
345
+ // <TProps extends string[], TEvents extends string[], T extends IComponent<TProps, TEvents>>(
346
+ // Base: new () => T, styles?: Styles | Styles[]
347
+ // ): new (attrs?: ComponentArgs<TProps, TEvents>) => T & IComponent<TProps, TEvents>;
348
+ // }
344
349
 
350
+ // useStyles<T extends IComponent>(styles: Styles | Styles[]): (Base: new () => T) => new () => T;
345
351
  // hasEvents<T extends IComponent>(styles: Styles | Styles[]): (Base: new () => T) => new () => T;
346
352
  // prop(target: any, propertyKey: string): void;
347
353
 
354
+ export type ComponentArgs<TProps extends Array<string>, TEvents extends Array<string>> = {
355
+ [key in TProps[number]]: any;
356
+ } & {
357
+ [key in TEvents[number]]: (...args: any[]) => void;
358
+ }
348
359
 
349
360
  /**
350
361
  * Interface for the dot object.
@@ -366,7 +377,13 @@ export interface IDotCore extends IDotDocument {
366
377
  // component<T extends IComponent>(Base: new (...args: Parameters<T['build']>) => T): new (...args: Parameters<T['build']>) => T;
367
378
  // useStyles<T extends IComponent>(styles: string|((css: IDotCss)=>IDotcssProp|string)): ((Base: new (...args: Parameters<T['build']>) => T) => new (...args: Parameters<T['build']>) => T);
368
379
 
369
- component: IComponentFactory;
380
+ // component: IComponentFactory;
381
+ // Works but doesn't infer types from the component.
382
+ // There's room for improvement here but it's not clear to me how to do it.
383
+ // What I'd like to do is have the types tied to the IComponent interface rather than the component factory function.
384
+ component<TProps extends string[] = [], TEvents extends string[] = []>(Base: new () => IComponent)
385
+ : new (attrs?: ComponentArgs<TProps, TEvents>) => IComponent & { new (attrs?: ComponentArgs<TProps, TEvents>): IComponent };
386
+
370
387
  useStyles(document: Document, styles: Styles): HTMLStyleElement;
371
388
  }
372
389