Skip to content

Commit

Permalink
simplify types and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Jan 8, 2024
1 parent cc913db commit 8869037
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions packages/serialize/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ export type CSSProperties = CSS.PropertiesFallback<number | string>
export type CSSPropertiesWithMultiValues<Props = unknown> = {
[K in keyof CSSProperties]:
| CSSProperties[K]
| ReadonlyArray<Extract<CSSProperties[K], string>>
| ((
props: Props
) => CSSProperties[K] | ReadonlyArray<Extract<CSSProperties[K], string>>)
| ReadonlyArray<CSSProperties[K]>
| ((props: Props) => CSSProperties[K] | ReadonlyArray<CSSProperties[K]>)
}

export type CSSPseudos<Props = unknown> = {
Expand Down
9 changes: 7 additions & 2 deletions packages/serialize/types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ serializeStyles(
{}
)
// $ExpectType SerializedStyles
serializeStyles<{ vars: { background: string; foreground: string } }>([
serializeStyles<{
vars: { background: string; foreground: string; step: number }
}>([
{
display: () => ['-webkit-flex', 'flex'],
backgroundColor: ({ vars }) => vars.background,
color: ({ vars }) => vars.foreground,
lineHeight: ({ vars }) => 1.2,
'--css-var': ({ vars }) => vars.foreground,
'--spacing': () => 1,
'--step': ({ vars }) => `calc(${vars.step} * var(--spacing))`,
'&:hover': {
backgroundColor: ({ vars }) => vars.foreground,
color: ({ vars }) => vars.background
Expand All @@ -58,6 +61,8 @@ serializeStyles()
// $ExpectError
serializeStyles({})
// $ExpectError
serializeStyles([{ borderCollapse: () => 'unknown' }])
// $ExpectError
serializeStyles({}, {})

let cssObject: CSSObject = {
Expand Down

0 comments on commit 8869037

Please sign in to comment.