From 7f2e6543edb9a41025bc0d7f6996669ad8ba13c8 Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Thu, 19 Aug 2021 11:14:50 +0200 Subject: [PATCH] Add typings for class component state attribute (#2995) * Add `state` typings to class components --- js/src/common/Component.ts | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/js/src/common/Component.ts b/js/src/common/Component.ts index 4b5a59947..09b91b019 100644 --- a/js/src/common/Component.ts +++ b/js/src/common/Component.ts @@ -29,7 +29,7 @@ export interface ComponentAttrs extends Mithril.Attributes {} * * @see https://mithril.js.org/components.html */ -export default abstract class Component implements Mithril.ClassComponent { +export default abstract class Component implements Mithril.ClassComponent { /** * The root DOM element for the component. */ @@ -40,48 +40,61 @@ export default abstract class Component): Mithril.Children; + abstract view(vnode: Mithril.Vnode): Mithril.Children; /** * @inheritdoc */ - oninit(vnode: Mithril.Vnode) { + oninit(vnode: Mithril.Vnode) { this.setAttrs(vnode.attrs); } /** * @inheritdoc */ - oncreate(vnode: Mithril.VnodeDOM) { + oncreate(vnode: Mithril.VnodeDOM) { this.element = vnode.dom; } /** * @inheritdoc */ - onbeforeupdate(vnode: Mithril.VnodeDOM) { + onbeforeupdate(vnode: Mithril.VnodeDOM) { this.setAttrs(vnode.attrs); } /** * @inheritdoc */ - onupdate(vnode: Mithril.VnodeDOM) {} + onupdate(vnode: Mithril.VnodeDOM) {} /** * @inheritdoc */ - onbeforeremove(vnode: Mithril.VnodeDOM) {} + onbeforeremove(vnode: Mithril.VnodeDOM) {} /** * @inheritdoc */ - onremove(vnode: Mithril.VnodeDOM) {} + onremove(vnode: Mithril.VnodeDOM) {} /** * Returns a jQuery object for this component's element. If you pass in a @@ -118,7 +131,7 @@ export default abstract class Component