Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix vnode type coercion #4158

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 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 Expand Up @@ -243,9 +242,8 @@ export function h(
| null,
...children: ComponentChildren[]
): VNode<
| (JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>)
| null
| JSXInternal.DOMAttributes<HTMLInputElement> &
ClassAttributes<HTMLInputElement>
>;
export function h<
P extends JSXInternal.HTMLAttributes<T>,
Expand All @@ -254,15 +252,15 @@ export function h<
type: keyof JSXInternal.IntrinsicElements,
props: (ClassAttributes<T> & P) | null,
...children: ComponentChildren[]
): VNode<(ClassAttributes<T> & P) | null>;
): VNode<ClassAttributes<T> & P>;
export function h<
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 h<T extends HTMLElement>(
type: string,
props:
Expand All @@ -281,7 +279,7 @@ export function h<P>(
type: ComponentType<P>,
props: (Attributes & P) | null,
...children: ComponentChildren[]
): VNode<(Attributes & P) | null>;
): VNode<Attributes & P>;
export namespace h {
export import JSX = JSXInternal;
}
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