Skip to content

Commit cfe87ed

Browse files
committed
Fix selector typing
1 parent dbb6fe9 commit cfe87ed

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"version": "1.0.12",
2020
"type": "module",
2121
"scripts": {
22-
"lint": "eslint",
22+
"lint": "eslint && tsc --noEmit",
2323
"build": "tsc && vite build"
2424
},
2525
"publishConfig": {

packages/react/src/types/props/__tests__/index.test-d.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { DevupCommonProps, DevupComponentProps } from '..'
1+
import { Property } from 'csstype'
2+
3+
import type { ResponsiveValue } from '../../responsive-value'
4+
import type { DevupCommonProps, DevupComponentProps, DevupProps } from '..'
5+
import type { Selectors } from '../selector'
26

37
describe('index', () => {
48
it('DevupCommonProps', () => {
@@ -8,6 +12,16 @@ describe('index', () => {
812
})
913
})
1014

15+
it('DevupProps', () => {
16+
expectTypeOf<DevupProps>()
17+
.toHaveProperty('bg')
18+
.toEqualTypeOf<ResponsiveValue<Property.Background>>()
19+
})
20+
21+
it('Selectors', () => {
22+
expectTypeOf<Selectors>().toHaveProperty('&:hover')
23+
})
24+
1125
it('DevupCommonProps _selector', () => {
1226
assertType<DevupComponentProps<'div'>>({
1327
_hover: {

packages/react/src/types/props/selector/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type CamelCase<S extends string> =
1313

1414
type PascalCase<S extends string> = Capitalize<CamelCase<S>>
1515

16-
type SelectorProps = ResponsiveValue<DevupProps | string | false>
16+
export type SelectorProps<T = DevupProps> = ResponsiveValue<T | string | false>
1717
export type DevupThemeSelectorProps = keyof DevupTheme extends undefined
1818
? Record<`_theme${string}`, SelectorProps>
1919
: {
@@ -24,22 +24,29 @@ type NormalSelector = Exclude<
2424
Pseudos,
2525
`:-${string}` | `::-${string}` | `${string}()`
2626
>
27-
type ExtractSelector<T> = T extends `::${infer R}`
27+
type ExtractSelector<T = NormalSelector> = T extends `::${infer R}`
2828
? R
2929
: T extends `:${infer R}`
3030
? R
3131
: never
3232
export type CommonSelectorProps = {
33-
[K in ExtractSelector<NormalSelector> as
33+
[K in ExtractSelector as
3434
| `_${CamelCase<K>}`
3535
| `_group${PascalCase<K>}`]?: SelectorProps
3636
}
3737

38+
export type Selectors = Partial<
39+
Record<
40+
(string & {}) | `&${NormalSelector}` | `_${CamelCase<ExtractSelector>}`,
41+
SelectorProps
42+
>
43+
>
44+
3845
export interface DevupSelectorProps extends CommonSelectorProps {
3946
// media query
4047
_print?: SelectorProps
4148

42-
selectors?: Record<string, SelectorProps>
49+
selectors?: Selectors
4350

4451
styleOrder?: number
4552
}

packages/react/src/utils/__tests__/css.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ describe('css', () => {
66
expect(() => css('class name' as any)).toThrowError(
77
'Cannot run on the runtime',
88
)
9-
expect(() => css()).toThrowError('Cannot run on the runtime')
9+
expect(() =>
10+
css({
11+
selectors: {
12+
'&::after': {},
13+
},
14+
}),
15+
).toThrowError('Cannot run on the runtime')
1016
})
1117
})

0 commit comments

Comments
 (0)