Skip to content

Commit 382585d

Browse files
committed
refactor: 更新class style类型
1 parent 364ac94 commit 382585d

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

src/simple-props/composables.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import {
2-
camelize,
3-
type CSSProperties,
4-
getCurrentInstance,
5-
useAttrs,
6-
useSlots,
7-
} from 'vue'
1+
import { camelize, getCurrentInstance, useAttrs, useSlots } from 'vue'
2+
import type { ClassAndStyleProps } from '@/type'
83

94
export function camelizePropKey(p: string | symbol): string | symbol {
105
if (typeof p === 'string') {
@@ -46,7 +41,6 @@ export function useProps<T>(): T {
4641
} else {
4742
return Reflect.get(getProps(), key, receiver)
4843
}
49-
return Reflect.get(getProps(), key, receiver)
5044
},
5145
ownKeys() {
5246
return [
@@ -85,12 +79,7 @@ function getSlotName(p: PropertyKey) {
8579
return p.slice(6).replace(/^[A-Z]/, (s) => s.toLowerCase())
8680
}
8781

88-
export interface ClassAndStyle {
89-
class?: string
90-
style?: CSSProperties
91-
}
92-
93-
export function useClassAndStyle(): ClassAndStyle {
82+
export function useClassAndStyle(): ClassAndStyleProps {
9483
const instance = getCurrentInstance()
9584
if (!instance) {
9685
throw new Error('useClassAndStyle must be called inside setup()')

src/simple-props/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import {
55
import type { ComponentType, FunctionalComponent } from './types'
66
import { useProps } from './composables'
77

8-
export {
9-
type ClassAndStyle,
10-
useClassAndStyle,
11-
camelizePropKey,
12-
} from './composables'
8+
export { useClassAndStyle, camelizePropKey } from './composables'
139
export * from './types'
1410

1511
export function defineComponent<T extends Record<any, any>>(

src/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export type ComponentSlots<T extends { props: any }> = NonNullable<
7373
/** 为了阻止ts把不相关的类也解析到metadata数据中,用这个工具类型包装一下类 */
7474
export type ClassType<T> = T
7575

76-
export type ClassAndStyleProps = {
76+
export interface ClassAndStyleProps {
7777
class?: any
7878
style?: StyleValue
7979
[name: string]: any

0 commit comments

Comments
 (0)