Skip to content

Commit

Permalink
Sprinkles: Fix some minor type issues (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles authored May 6, 2021
1 parent fce9695 commit 45a6eef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changeset/neat-buttons-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@vanilla-extract/sprinkles': patch
---

Fix some minor type issues

- Better support passing config to `createAtomicStyles` that was not defined inline
- Remove array methods being exposed on properties using number arrays
4 changes: 2 additions & 2 deletions packages/sprinkles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type BaseConditions = { [conditionName: string]: Condition };
type AtomicProperties = {
[Property in keyof CSSProperties]?:
| Record<string, CSSProperties[Property]>
| Array<CSSProperties[Property]>;
| ReadonlyArray<CSSProperties[Property]>;
};

type ShorthandOptions<
Expand Down Expand Up @@ -51,7 +51,7 @@ type ConditionalAtomicOptions<
};

type Values<Property, Result> = {
[Value in Property extends Array<any>
[Value in Property extends ReadonlyArray<any>
? Property[number]
: keyof Property]: Result;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/sprinkles/index.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const conditionalAtomicStyles = createAtomicStyles({
display: ['block', 'none', 'flex'],
paddingTop: spacing,
paddingBottom: spacing,
opacity: [0, 1],
opacity: [0, 1] as const,
},
shorthands: {
paddingY: ['paddingBottom', 'paddingTop'],
Expand Down
14 changes: 13 additions & 1 deletion tests/sprinkles/spinkles-type-tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is for validating types, it is not designed to be executed
*/

import { createAtomicStyles } from '@vanilla-extract/sprinkles';
import { createAtomsFn } from '@vanilla-extract/sprinkles/createAtomsFn';

import {
Expand Down Expand Up @@ -95,4 +95,16 @@ import {
atoms({
marginY: { mobile: 'medium' },
});

// @ts-expect-error - Property defined with numbers should not allow array methods
atoms({ opacity: 'forEach' });

const atomicConfig = {
properties: {
flexDirection: ['row', 'column'],
},
} as const;

// Valid value - config defined outside the createAtomicStyles function
createAtomicStyles(atomicConfig);
};

0 comments on commit 45a6eef

Please sign in to comment.