Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TS PropertyValue and ScaleValue types in the react package #835

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions packages/react/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type CSSProperties = CSSUtil.CSSProperties
export type DefaultThemeMap = Config.DefaultThemeMap

/** Returns a Style interface from a configuration, leveraging the given media and style map. */

export type CSS<
Config extends {
media?: {}
Expand All @@ -33,26 +32,26 @@ export type CSS<
export type ComponentProps<Component> = Component extends ((...args: any[]) => any) ? Parameters<Component>[0] : never

/** Returns a type that expects a value to be a kind of CSS property value. */
export type PropertyValue<K extends keyof CSSUtil.CSSProperties, C = null> = (
C extends null
? { readonly [CSSUtil.$$PropertyValue]: K }
: C extends { [K: string]: any }
export type PropertyValue<Property extends keyof CSSUtil.CSSProperties, Config = null> = (
Config extends null
? { readonly [K in CSSUtil.$$PropertyValue]: Property }
: Config extends { [K: string]: any }
? CSSUtil.CSS<
C['media'],
C['theme'],
C['themeMap'],
C['utils']
>[K]
Config['media'],
Config['theme'],
Config['themeMap'],
Config['utils']
>[Property]
: never
)

/** Returns a type that expects a value to be a kind of theme scale value. */
export type ScaleValue<K, C = null> = (
C extends null
? { readonly [CSSUtil.$$ScaleValue]: K }
: C extends { [K: string]: any }
? K extends keyof C['theme']
? `$${string & keyof C['theme'][K]}`
export type ScaleValue<Scale, Config = null> = (
Config extends null
? { readonly [K in CSSUtil.$$ScaleValue]: Scale }
: Config extends { [K: string]: any }
? Scale extends keyof Config['theme']
? `$${string & keyof Config['theme'][Scale]}`
: never
: never
)
Expand Down
2 changes: 1 addition & 1 deletion packages/test/Issue-813-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { createStitches } from '@stitches/react'
import * as Stitches from '@stitches/react'

const { config, styled } = createStitches({
export const { config, styled } = createStitches({
theme: {
colors: {
primary: 'transparent'
Expand Down