Skip to content

Commit 45a6eef

Browse files
authored
Sprinkles: Fix some minor type issues (#98)
1 parent fce9695 commit 45a6eef

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

.changeset/neat-buttons-shave.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@vanilla-extract/sprinkles': patch
3+
---
4+
5+
Fix some minor type issues
6+
7+
- Better support passing config to `createAtomicStyles` that was not defined inline
8+
- Remove array methods being exposed on properties using number arrays

packages/sprinkles/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type BaseConditions = { [conditionName: string]: Condition };
1818
type AtomicProperties = {
1919
[Property in keyof CSSProperties]?:
2020
| Record<string, CSSProperties[Property]>
21-
| Array<CSSProperties[Property]>;
21+
| ReadonlyArray<CSSProperties[Property]>;
2222
};
2323

2424
type ShorthandOptions<
@@ -51,7 +51,7 @@ type ConditionalAtomicOptions<
5151
};
5252

5353
type Values<Property, Result> = {
54-
[Value in Property extends Array<any>
54+
[Value in Property extends ReadonlyArray<any>
5555
? Property[number]
5656
: keyof Property]: Result;
5757
};

tests/sprinkles/index.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const conditionalAtomicStyles = createAtomicStyles({
5050
display: ['block', 'none', 'flex'],
5151
paddingTop: spacing,
5252
paddingBottom: spacing,
53-
opacity: [0, 1],
53+
opacity: [0, 1] as const,
5454
},
5555
shorthands: {
5656
paddingY: ['paddingBottom', 'paddingTop'],

tests/sprinkles/spinkles-type-tests.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This file is for validating types, it is not designed to be executed
33
*/
4-
4+
import { createAtomicStyles } from '@vanilla-extract/sprinkles';
55
import { createAtomsFn } from '@vanilla-extract/sprinkles/createAtomsFn';
66

77
import {
@@ -95,4 +95,16 @@ import {
9595
atoms({
9696
marginY: { mobile: 'medium' },
9797
});
98+
99+
// @ts-expect-error - Property defined with numbers should not allow array methods
100+
atoms({ opacity: 'forEach' });
101+
102+
const atomicConfig = {
103+
properties: {
104+
flexDirection: ['row', 'column'],
105+
},
106+
} as const;
107+
108+
// Valid value - config defined outside the createAtomicStyles function
109+
createAtomicStyles(atomicConfig);
98110
};

0 commit comments

Comments
 (0)