Skip to content

Commit 684df31

Browse files
author
Ajit Kumar
committed
fix(types)
1 parent e613277 commit 684df31

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

index.d.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface HTMLElementAttributes {
5858
/**
5959
* A reference to the element
6060
*/
61-
ref?: import('html-tag-js/ref').Ref;
61+
ref?: import('html-tag-js/ref').RefConstructor;
6262
/**
6363
* Sets content of the element.
6464
* @example $div.content = tag('span', 'Hello World!');
@@ -560,7 +560,7 @@ declare module 'html-tag-js' {
560560
}
561561

562562
declare module 'html-tag-js/ref' {
563-
interface Ref {
563+
export interface RefConstructor {
564564
/**
565565
* Element reference
566566
*/
@@ -597,17 +597,17 @@ declare module 'html-tag-js/ref' {
597597
* @param event event name
598598
* @param cb callback function
599599
*/
600-
on(event: 'ref', cb: (this: Ref, ref: HTMLElement) => void): void;
600+
on(event: 'ref', cb: (this: RefConstructor, ref: HTMLElement) => void): void;
601601
/**
602602
* Remove event listener
603603
* @param event event name
604604
* @param cb callback function
605605
*/
606-
off(event: 'ref', cb: (this: Ref, ref: HTMLElement) => void): void;
606+
off(event: 'ref', cb: (this: RefConstructor, ref: HTMLElement) => void): void;
607607
/**
608608
* Called when reference is set
609609
*/
610-
onref: (this: Ref, ref: HTMLElement) => void;
610+
onref: (this: RefConstructor, ref: HTMLElement) => void;
611611
/**
612612
* Get the classList
613613
* If the element is not yet created
@@ -677,17 +677,37 @@ declare module 'html-tag-js/ref' {
677677
content: Node | Array<Node>;
678678
}
679679

680-
export default function Ref(onref?: (this: Ref, element: HTMLElement) => void): Ref;
680+
const Ref: {
681+
(onref?: (this: RefConstructor, element: HTMLElement) => void): RefConstructor;
682+
/**
683+
* Check if the value is object of RefConstructor
684+
* @param value Object to check
685+
* @returns
686+
*/
687+
isRef: (value: any) => boolean;
688+
}
689+
690+
export default Ref;
681691
}
682692

683693
declare module 'html-tag-js/reactive' {
684-
interface Reactive<T = string> extends Text {
694+
export interface ReactiveConstructor<T = string> extends Text {
685695
value: T;
686-
onChange: (this: Reactive<T>, value: T) => void;
696+
onChange: (this: ReactiveConstructor<T>, value: T) => void;
687697
toString: () => string;
688698
}
689699

690-
export default function Reactive<T = any>(initialValue?: T): Reactive<T>;
700+
const Reactive: {
701+
<T = string>(value: T): ReactiveConstructor<T>;
702+
/**
703+
* Check if the value is object of ReactiveConstructor
704+
* @param value Object to check
705+
* @returns
706+
*/
707+
isReactive: (value: any) => boolean;
708+
};
709+
710+
export default Reactive;
691711
}
692712

693713
declare namespace JSX {

index.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/// <reference path="./index.d.ts" />
22

3-
import Ref from 'html-tag-js/ref';
43
import Reactive from 'html-tag-js/reactive';
4+
import Ref from 'html-tag-js/ref';
55

66
const val = Reactive(100);
77

8+
Reactive.isReactive(val); // true
9+
810
const test = <div ref={Ref()} className='test' xyz="test" style={{
911
color: 'red'
1012
}}></div>;
@@ -13,4 +15,5 @@ test.append(val);
1315

1416
test.content = [
1517
<p>Hello</p>
16-
];
18+
];
19+

0 commit comments

Comments
 (0)