Skip to content

Commit 32cd515

Browse files
committed
fix types
1 parent 5862bd8 commit 32cd515

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/class.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import type { ComponentPublicInstance } from 'vue'
2-
import type { IdentityType, Identity, IdentitySymbol } from './identity'
2+
import type { IdentityType, Identity,IdentityAny, IdentitySymbol } from './identity'
33
export type VueCons<RawInstance extends Identity = Identity, IT extends IdentityType = { props: {}, events: {} }, Bundle = IT['props'] & { [index in keyof IT['events']as `on${Capitalize<index & string>}`]?: IT['events'][index] extends Function ? IT['events'][index] : { (param: IT['events'][index]): any } }> = {
44
new(): ComponentPublicInstance<Bundle> & Identity<IT> & Omit<RawInstance, typeof IdentitySymbol>
55
}
66

7+
export type VueConsAny<RawInstance extends Identity = Identity, IT extends IdentityType = { props: {}, events: {} }, Bundle = IT['props'] & { [index in keyof IT['events']as `on${Capitalize<index & string>}`]?: IT['events'][index] extends Function ? IT['events'][index] : { (param: IT['events'][index]): any } }> = {
8+
new(): ComponentPublicInstance<Bundle> & IdentityAny<IT> & Omit<RawInstance, typeof IdentitySymbol> & { [index: PropertyKey]: any }
9+
}
10+
711
export const Base = class {
812

913
} as VueCons

src/identity.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ export type IdentityType = {
88
type AssertIs<O, T extends O> = T
99

1010
export interface Identity<T extends IdentityType = IdentityType> {
11-
[index: PropertyKey]: any
1211
[IdentitySymbol]: T
1312
}
1413

14+
export interface IdentityAny<T extends IdentityType = IdentityType> extends Identity<T> {
15+
[index: PropertyKey]: any
16+
}
17+
1518
type MergeRecord<N extends Record<string, any>, O extends Record<string, any>> = {
1619
[I in (keyof N) | (keyof O)]: I extends keyof N ? N[I] : I extends keyof O ? O[I] : never
1720
}

src/option/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { VueCons } from '../class'
1+
import type { VueConsAny } from '../class'
22
import type { OptionBuilder } from '../optionBuilder'
33
import { filterNames, getValidOwnPropertyNames } from '../utils'
44
import { obtainSlot } from '../slot'
5-
export function build(cons: VueCons, optionBuilder: OptionBuilder) {
5+
export function build(cons: VueConsAny, optionBuilder: OptionBuilder) {
66
optionBuilder.data ??= {}
77
const sample = new cons()
88
let names = getValidOwnPropertyNames(sample, (des, name) => {

src/option/methodsAndHooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { VueCons } from '../class'
1+
import type { VueConsAny } from '../class'
22
import type { OptionBuilder } from '../optionBuilder'
33
import { toComponentReverse, filterNames, getValidOwnPropertyNames, optionNullableMemberDecorator } from '../utils'
44
import { obtainSlot } from '../slot'
@@ -29,7 +29,7 @@ export const decorator = optionNullableMemberDecorator(function (proto: any, nam
2929
map.set(name, null)
3030
})
3131

32-
export function build(cons: VueCons, optionBuilder: OptionBuilder) {
32+
export function build(cons: VueConsAny, optionBuilder: OptionBuilder) {
3333
const slot = obtainSlot(cons.prototype)
3434
const protoArr = toComponentReverse(cons.prototype)
3535
const map = slot.obtainMap('hooks')

src/utils.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import type { Identity } from './identity'
1+
import type { IdentityAny } from './identity'
22
import { compatibleMemberDecorator, compatibleClassDecorator } from './deco3/utils';
33
import { type VueCons, Base } from './class';
44
import { getSlot, type Slot, type SlotMapNames } from './slot'
55

6-
export function getPrototypeOf(proto: Identity): Identity | null {
6+
export function getPrototypeOf(proto: IdentityAny): IdentityAny | null {
77
const p = Object.getPrototypeOf(proto)
88
if (!(p instanceof Base)) {
99
return null
1010
}
1111
return p
1212
}
1313

14-
export function toComponentReverse(proto: Identity) {
15-
const arr: Identity[] = []
16-
let curr: Identity | null = proto
14+
export function toComponentReverse(proto: IdentityAny) {
15+
const arr: IdentityAny[] = []
16+
let curr: IdentityAny | null = proto
1717
do {
1818
arr.unshift(curr)
1919
curr = getPrototypeOf(curr)
2020
} while (curr !== null && !getSlot(curr))
2121
return arr
2222
}
2323

24-
export function getSuperSlot(proto: Identity) {
24+
export function getSuperSlot(proto: IdentityAny) {
2525
let curr = getPrototypeOf(proto)
2626

2727
while (curr !== null) {
@@ -86,11 +86,11 @@ export function getProviderFunction(provide: any): () => {} {
8686
export function optionNullableMemberDecorator<T>(handler: { (proto: any, name: string, option?: T): any }) {
8787
function decorator(): any
8888
function decorator(option: T): any//option
89-
function decorator(proto: Identity, name: any): any//deco stage 2
89+
function decorator(proto: IdentityAny, name: any): any//deco stage 2
9090
function decorator(value: any, ctx: ClassMemberDecoratorContext): any //deco stage 3
91-
function decorator(optionOrProtoOrValue?: T | Identity | any, nameOrCtx?: string | ClassMemberDecoratorContext): any {
91+
function decorator(optionOrProtoOrValue?: T | IdentityAny | any, nameOrCtx?: string | ClassMemberDecoratorContext): any {
9292
if (nameOrCtx) {//no option
93-
const protoOrValue = optionOrProtoOrValue as Identity | any
93+
const protoOrValue = optionOrProtoOrValue as IdentityAny | any
9494
compatibleMemberDecorator(function (proto: any, name: any) {
9595
handler(proto, name)
9696
})(protoOrValue, nameOrCtx)

0 commit comments

Comments
 (0)