Skip to content

Commit

Permalink
fix: support typing undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Aug 9, 2021
1 parent d1a80d5 commit 04bfc04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 32 deletions.
73 changes: 42 additions & 31 deletions packages/core/types/css-util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type CSS<
| TokenByPropertyName<K, Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
| undefined
)
}
// known utility styles
Expand All @@ -40,35 +41,43 @@ export type CSS<
: (
| (
Utils[K] extends (arg: infer P) => any
? P extends any[]
? (
$$PropertyValue extends keyof P[0]
? (
| ValueByPropertyName<P[0][$$PropertyValue]>
| TokenByPropertyName<P[0][$$PropertyValue], Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
)
: $$ScaleValue extends keyof P[0]
? (
| TokenByScaleName<P[0][$$ScaleValue], Theme>
| ThemeUtil.ScaleValue
)
: never
)[]
: $$PropertyValue extends keyof P
? (
| ValueByPropertyName<P[$$PropertyValue]>
| TokenByPropertyName<P[$$PropertyValue], Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
)
: $$ScaleValue extends keyof P
? (
| TokenByScaleName<P[$$ScaleValue], Theme>
| ThemeUtil.ScaleValue
)
: never
? (
P extends any[]
? (
$$PropertyValue extends keyof P[0]
? (
| ValueByPropertyName<P[0][$$PropertyValue]>
| TokenByPropertyName<P[0][$$PropertyValue], Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
| undefined
)
: $$ScaleValue extends keyof P[0]
? (
| TokenByScaleName<P[0][$$ScaleValue], Theme>
| ThemeUtil.ScaleValue
| undefined
)
: never
)[]
| P
: $$PropertyValue extends keyof P
? (
| ValueByPropertyName<P[$$PropertyValue]>
| TokenByPropertyName<P[$$PropertyValue], Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
| undefined
)
: $$ScaleValue extends keyof P
? (
| TokenByScaleName<P[$$ScaleValue], Theme>
| ThemeUtil.ScaleValue
| undefined
)
: never
)
| P
: never
)
)
Expand All @@ -86,12 +95,14 @@ export type CSS<
: (
| CSS.Globals
| Util.Index
| undefined
)
)
}
// unknown css declaration styles
& {
[K in string]: number | string | CSS<Media, Theme, ThemeMap, Utils> | {}
/** Unknown property. */
[K in string]: number | string | CSS<Media, Theme, ThemeMap, Utils> | {} | undefined
}
)

Expand All @@ -105,7 +116,7 @@ export type KnownCSS<
> = (
// nested at-rule css styles
& {
[K in Util.Prefixed<'@', keyof Media>]?: KnownCSS<Media, Theme, ThemeMap, Utils>
[K in Util.Prefixed<'@', keyof Media>]?: CSS<Media, Theme, ThemeMap, Utils>
}
// known property styles
& {
Expand Down
8 changes: 7 additions & 1 deletion packages/react/types/css-util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type CSS<
| TokenByPropertyName<K, Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
| undefined
)
}
// known utility styles
Expand All @@ -49,11 +50,13 @@ export type CSS<
| TokenByPropertyName<P[0][$$PropertyValue], Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
| undefined
)
: $$ScaleValue extends keyof P[0]
? (
| TokenByScaleName<P[0][$$ScaleValue], Theme>
| ThemeUtil.ScaleValue
| undefined
)
: never
)[]
Expand All @@ -64,11 +67,13 @@ export type CSS<
| TokenByPropertyName<P[$$PropertyValue], Theme, ThemeMap>
| CSS.Globals
| ThemeUtil.ScaleValue
| undefined
)
: $$ScaleValue extends keyof P
? (
| TokenByScaleName<P[$$ScaleValue], Theme>
| ThemeUtil.ScaleValue
| undefined
)
: never
)
Expand All @@ -90,13 +95,14 @@ export type CSS<
: (
| CSS.Globals
| Util.Index
| undefined
)
)
}
// unknown css declaration styles
& {
/** Unknown property. */
[K in string]: number | string | CSS<Media, Theme, ThemeMap, Utils> | {}
[K in string]: number | string | CSS<Media, Theme, ThemeMap, Utils> | {} | undefined
}
)

Expand Down

0 comments on commit 04bfc04

Please sign in to comment.