Skip to content

Commit c538482

Browse files
committed
tsx type
1 parent 4167e49 commit c538482

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

src/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ export { createDecorator } from './custom/custom'
1313
export { mixins } from './mixins'
1414
import type { ComponentPublicInstance } from 'vue'
1515
import type { OptionBuilder } from './optionBuilder'
16-
16+
export { TSX } from './tsx/type'
1717
const IdentifySymbol = Symbol('vue-facing-decorator-identify')
1818
export interface BaseTypeIdentify {
1919
[IdentifySymbol]: undefined
2020
}
21-
export function TSX<Properties extends {} = {}, Events extends {} = {}>() {
22-
type Bundle = Properties & { [index in keyof Events as `on${Capitalize<index & string>}`]: Events[index] extends Function ? Events[index] : { (param: Events[index]): any } }
23-
return function <C extends VueCons>(cons: C) {
24-
return cons as unknown as {
25-
new(): Omit<ComponentPublicInstance<(InstanceType<C>['$props']) & Bundle>, keyof Bundle> & InstanceType<C>//& ComponentPublicInstance & BaseTypeIdentify
26-
}
27-
}
28-
}
21+
// export function TSX<Properties extends {} = {}, Events extends {} = {}>() {
22+
// type TEvents = { [index in keyof Events as `on${Capitalize<index & string>}`]: Events[index] extends Function ? Events[index] : { (param: Events[index]): any } }
23+
// return function <C extends VueCons>(cons: C) {
24+
// return cons as unknown as {
25+
// new(): ComponentPublicInstance<Properties & TEvents> & InstanceType<C>//& ComponentPublicInstance & BaseTypeIdentify
26+
// }
27+
// }
28+
// }
2929

3030
export type VueCons<T = {}> = {
3131
new(optionBuilder: OptionBuilder, vueInstance: any): ComponentPublicInstance & BaseTypeIdentify & T

src/tsx/type.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { ComponentPublicInstance } from 'vue'
2+
import type { VueCons } from '../index'
3+
export function TSX<Properties extends {} = {}, Events extends {} = {}>() {
4+
type TEvents = { [index in keyof Events as `on${Capitalize<index & string>}`]: Events[index] extends Function ? Events[index] : { (param: Events[index]): any } }
5+
return function <C extends VueCons>(cons: C) {
6+
return cons as unknown as {
7+
new(): ComponentPublicInstance<Properties & TEvents> & InstanceType<C>
8+
}
9+
}
10+
}

test/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"composite": false,
2020
"declaration": true,
2121
"declarationMap": true,
22-
"noUnusedLocals": false
22+
"noUnusedLocals": false,
23+
"jsx": "preserve"
2324
},
2425
"include": [
2526
"./**/*.ts",

test/tsx/attributeTypes.ts renamed to test/tsx/attributeTypes.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ class TsxAttributeTypes extends TSX<Props, Events>()(Base) implements Props {
1414
p!: string
1515
}
1616

17-
export default {}
17+
export default {}
18+
19+
const template = <TsxAttributeTypes p="" onE={() => { }} onE2={() => { }}></TsxAttributeTypes>

0 commit comments

Comments
 (0)