Skip to content

Commit

Permalink
fix vnode type coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 12, 2023
1 parent 4b1a7e9 commit dfb6c32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ export function createElement(
| null,
...children: ComponentChildren[]
): VNode<
| (JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>)
| null
| JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>
>;
export function createElement<
P extends JSXInternal.HTMLAttributes<T>,
Expand All @@ -206,15 +205,15 @@ export function createElement<
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<(ClassAttributes<T> & P) | null>;
): VNode<ClassAttributes<T> & P>;
export function createElement<
P extends JSXInternal.SVGAttributes<T>,
T extends HTMLElement
>(
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<(ClassAttributes<T> & P) | null>;
): VNode<ClassAttributes<T> & P>;
export function createElement<T extends HTMLElement>(
type: string,
props:
Expand Down
12 changes: 9 additions & 3 deletions test/ts/VNode-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ describe('VNode TS types', () => {
expect(actual).to.include.all.keys('type', 'props', 'key');
});

it('has a nodeName of string when html element', () => {
const div = <div>Hi!</div>;
expect(div.type).to.equal('div');
it('is returned by h', () => {
const actual = <div className="wow" />;
expect(actual).to.include.all.keys('type', 'props', 'key');
});

it('createElement conforms to the VNode type', () => {
const arr: VNode[] = [];
arr.push(createElement('div', null));
expect(true).to.be.true;
});

it('has a nodeName equal to the construction function when SFC', () => {
Expand Down

0 comments on commit dfb6c32

Please sign in to comment.