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

Add distributive condition to Assign util #822

Merged
merged 2 commits into from
Oct 1, 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
20 changes: 18 additions & 2 deletions packages/react/tests/types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as Stitches from '../types/index'
import { createStitches } from '../types/index'

const { css, global, keyframes, styled, theme } = createStitches({
const { css, globalCss, keyframes, styled, theme } = createStitches({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file was erroring because global doesn't exist so fixed this while I was here too.

utils: {
mx: (value: Stitches.PropertyValue<'marginLeft'>) => ({
marginLeft: value,
Expand Down Expand Up @@ -54,7 +54,7 @@ keyframes({
},
})

global({
globalCss({
body: {
backgroundColor: '$gray300',
'@bp1': {
Expand Down Expand Up @@ -166,3 +166,19 @@ void function Test() {
}} />
)
}

/* -------------------------------------------------------------------------------------------------
* Issue #821
* -----------------------------------------------------------------------------------------------*/

type UnionProps = { type: 'single', collapsible: boolean; } | { type: 'multiple' };
const UnionComponent: React.FC<UnionProps> = () => null
const StyledUnionComponent = styled(UnionComponent, {})

void function Test() {
<>
<StyledUnionComponent type="single" collapsible />
{/* @ts-expect-error */}
<StyledUnionComponent type="multiple" collapsible />
</>
}
2 changes: 1 addition & 1 deletion packages/react/types/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export type Prefixed<K extends string, T> = `${K}${Extract<T, boolean | number | string>}`

/** Returns an object from the given object assigned with the values of another given object. */
export type Assign<T1 = {}, T2 = {}> = Omit<T1, keyof T2> & T2
export type Assign<T1 = {}, T2 = {}> = T1 extends any ? Omit<T1, keyof T2> & T2 : never

/** Returns a widened value from the given value. */
export type Widen<T> =
Expand Down