Skip to content

Commit

Permalink
wip(types): remove h with HTMLElementTagNameMap
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Aug 8, 2024
1 parent 70bb336 commit c3148d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
23 changes: 12 additions & 11 deletions packages/dts-test/h.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ref,
resolveComponent,
} from 'vue'
import { describe, expectAssignable, expectType } from './utils'
import { describe, expectAssignable /*, expectType */ } from './utils'

describe('h inference w/ element', () => {
// key
Expand All @@ -35,16 +35,17 @@ describe('h inference w/ element', () => {
const slots = { default: () => {} } // RawSlots
h('div', {}, slots)
// events
h('div', {
onClick: e => {
expectType<MouseEvent>(e)
},
})
h('input', {
onFocus(e) {
expectType<FocusEvent>(e)
},
})
// fixed by xxxxxx
// h('div', {
// onClick: e => {
// expectType<MouseEvent>(e)
// },
// })
// h('input', {
// onFocus(e) {
// expectType<FocusEvent>(e)
// },
// })
})

describe('h inference w/ Fragment', () => {
Expand Down
30 changes: 16 additions & 14 deletions packages/runtime-core/src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,27 @@ interface Constructor<P = any> {
new (...args: any[]): { $props: P }
}

type HTMLElementEventHandler = {
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (
ev: HTMLElementEventMap[K],
) => any
}
// fixed by xxxxxx
// type HTMLElementEventHandler = {
// [K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (
// ev: HTMLElementEventMap[K],
// ) => any
// }

// The following is a series of overloads for providing props validation of
// manually written render functions.

// element
export function h<K extends keyof HTMLElementTagNameMap>(
type: K,
children?: RawChildren,
): VNode
export function h<K extends keyof HTMLElementTagNameMap>(
type: K,
props?: (RawProps & HTMLElementEventHandler) | null,
children?: RawChildren | RawSlots,
): VNode
// fixed by xxxxxx
// export function h<K extends keyof HTMLElementTagNameMap>(
// type: K,
// children?: RawChildren,
// ): VNode
// export function h<K extends keyof HTMLElementTagNameMap>(
// type: K,
// props?: (RawProps & HTMLElementEventHandler) | null,
// children?: RawChildren | RawSlots,
// ): VNode

// custom element
export function h(type: string, children?: RawChildren): VNode
Expand Down

0 comments on commit c3148d2

Please sign in to comment.