Skip to content

Commit 20528e9

Browse files
authoredMar 6, 2024
Fix inference of complex properties in cssMap (#1640)
* Fix type inferrence on `background` and other complex types. Fixes #1639 * chore: changeset * chore: update tests now that these aren't errors!
1 parent 5701b91 commit 20528e9

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed
 

‎.changeset/thick-shirts-tease.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/react': patch
3+
---
4+
5+
Better cssMap types: fix inference of complex types and adds descriptions to the type.

‎packages/react/src/create-strict-api/__tests__/index.test.tsx

+7-16
Original file line numberDiff line numberDiff line change
@@ -332,20 +332,6 @@ describe('createStrictAPI()', () => {
332332
// @ts-expect-error — This conflicts with the custom API, should be a different bg color
333333
xcss={cx(stylesInvalidRoot.primary, stylesValid.primary)}
334334
/>
335-
<Button
336-
testId="button-valid-root"
337-
// @ts-expect-error — For some reason the "background" property is being expanded to "string" instead of
338-
// staying narrowed as "var(--ds-surface-hover)" meaning it breaks when used with the strict
339-
// schema loaded XCSS prop. This is a bug and unexpected.
340-
xcss={stylesValidRoot.primary}
341-
/>
342-
<Button
343-
testId="button-valid-root-cx"
344-
// @ts-expect-error — For some reason the "background" property is being expanded to "string" instead of
345-
// staying narrowed as "var(--ds-surface-hover)" meaning it breaks when used with the strict
346-
// schema loaded XCSS prop. This is a bug and unexpected.
347-
xcss={cx(stylesValidRoot.primary, stylesValid.primary)}
348-
/>
349335
<Button
350336
testId="button-invalid-strict"
351337
// @ts-expect-error — TODO: This should conflict, but when `cssMap` conflicts, it gets a different type (this has `ApplySchema`, not the raw object), so this doesn't error? Weird…
@@ -356,15 +342,20 @@ describe('createStrictAPI()', () => {
356342
// @ts-expect-error — TODO: This should conflict, but when `cssMap` conflicts, it gets a different type (this has `ApplySchema`, not the raw object), so this doesn't error? Weird…
357343
xcss={cx(stylesInvalid.primary, stylesValid.primary)}
358344
/>
359-
<Button testId="button-valid" xcss={stylesValid.primary} />
360-
<Button testId="button-valid-cx" xcss={cx(stylesValid.primary, stylesValid.primary)} />
361345
<Button
362346
testId="button-invalid-direct"
363347
xcss={{
364348
// @ts-expect-error — This is not in the `createStrictAPI` schema—this should be a css variable.
365349
color: 'red',
366350
}}
367351
/>
352+
<Button testId="button-valid" xcss={stylesValid.primary} />
353+
<Button testId="button-valid-cx" xcss={cx(stylesValid.primary, stylesValid.primary)} />
354+
<Button testId="button-valid-root" xcss={stylesValidRoot.primary} />
355+
<Button
356+
testId="button-valid-root-cx"
357+
xcss={cx(stylesValidRoot.primary, stylesValid.primary)}
358+
/>
368359
</>
369360
);
370361

‎packages/react/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export type CSSPseudos = CSSPseudoElements | CSSPseudoClasses;
104104
* excess property check doesn't enable makers to circumvent the
105105
* system and pass in values they shouldn't.
106106
*/
107-
export type CSSProperties = Readonly<CSS.Properties<string | number>>;
107+
export type CSSProperties = Readonly<CSS.Properties<(string & object) | number>>;
108108

109109
/**
110110
* A stricter subset of the {@link CSSProperties} type that excludes

0 commit comments

Comments
 (0)
Please sign in to comment.