@@ -45,7 +45,7 @@ export interface Options extends preact.Options {
4545 _internal ?( internal : Internal , vnode : VNode | string ) : void ;
4646}
4747
48- export type CommitQueue = Internal [ ] ;
48+ export type CommitQueue = ComponentInternal [ ] ;
4949
5050// Redefine ComponentFactory using our new internal FunctionalComponent interface above
5151export type ComponentFactory < P > =
@@ -130,18 +130,13 @@ export interface VNode<P = {}> extends preact.VNode<P> {
130130 * An Internal is a persistent backing node within Preact's virtual DOM tree.
131131 * Think of an Internal like a long-lived VNode with stored data and tree linkages.
132132 */
133- export interface Internal < P = { } > {
134- type : string | ComponentType < P > ;
135- /** The props object for Elements/Components, and the string contents for Text */
136- props : ( P & { children : ComponentChildren } ) | string | number ;
133+ export interface BaseInternal < P = { } > {
137134 key : any ;
138135 ref : Ref < any > | null ;
139136 _prevRef : Ref < any > | null ;
140137
141138 /** Bitfield containing information about the Internal or its component. */
142139 flags : number ;
143- /** Polymorphic property to store extensions like hooks on */
144- data : object | PreactNode ;
145140 /** The function that triggers in-place re-renders for an internal */
146141 rerender : ( internal : Internal ) => void ;
147142
@@ -159,16 +154,52 @@ export interface Internal<P = {}> {
159154 _component : Component | null ;
160155 /** This Internal's distance from the tree root */
161156 _depth : number | null ;
162- /** Callbacks to invoke when this internal commits */
163- _commitCallbacks : Array < ( ) => void > ;
164- _stateCallbacks : Array < ( ) => void > ; // Only class components
165157}
166158
159+ export interface ComponentInternal < P = { } > extends BaseInternal < P > {
160+ type : ComponentType < P > ;
161+ props : P & { children : ComponentChildren } ;
162+ /** Polymorphic property to store extensions like hooks on */
163+ data : {
164+ /** Callbacks to invoke when this internal commits */
165+ _commitCallbacks : Array < ( ) => void > ;
166+ _stateCallbacks : Array < ( ) => void > ; // Only class components
167+ [ key : string ] : any ;
168+ } ;
169+ }
170+
171+ export interface RootInternal < P = { } >
172+ extends Exclude < ComponentInternal < P > , 'props' > {
173+ props : P & { children : ComponentChildren ; _parentDom : PreactNode } ;
174+ }
175+
176+ export interface DomInternal < P = { } > extends BaseInternal < P > {
177+ type : string ;
178+ /** The props object for Elements/Components, and the string contents for Text */
179+ props : ( P & { children : ComponentChildren } ) | string | number ;
180+ data : PreactNode ;
181+ }
182+
183+ export type Internal < P = { } > =
184+ | ComponentInternal < P >
185+ | DomInternal < P >
186+ | RootInternal < P > ;
187+
188+ export type isDomInternal < P = { } > = (
189+ internal : Internal < P >
190+ ) => internal is DomInternal < P > ;
191+ export type isComponentInternal < P = { } > = (
192+ internal : Internal < P >
193+ ) => internal is ComponentInternal < P > ;
194+ export type isRootInternal < P = { } > = (
195+ internal : Internal < P >
196+ ) => internal is RootInternal < P > ;
197+
167198export interface Component < P = { } , S = { } > extends preact . Component < P , S > {
168199 // When component is functional component, this is reset to functional component
169200 constructor : ComponentType < P > ;
170201 state : S ; // Override Component["state"] to not be readonly for internal use, specifically Hooks
171- _internal ?: Internal < P > | null ;
202+ _internal ?: ComponentInternal < P > | null ;
172203 _nextState ?: S | null ; // Only class components
173204 /** Only used in the devtools to later dirty check if state has changed */
174205 _prevState ?: S | null ;
0 commit comments