Skip to content

Commit 5dca5c5

Browse files
authoredDec 22, 2023
Export CSSPseudos, CSSProperties, StrictCSSProperties types for a strict XCSSProp implementation. (#1600)
* Export `CSSPseudos, CSSProperties, StrictCSSProperties` types for a strict `XCSSProp` implementation. To avoid the complexity of requiring `ReturnType<typeof XCSSProp<…>>` when creating a `createStrictAPI().XCSSProp` and `props.xcss` implementation, being able to use these types in generics are helpful. The example usage is: ```tsx const { XCSSProp, css, cssMap, cx } = createStrictAPI<…>(); export type StrictXCSSProp< TAllowedProperties extends keyof StrictCSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends { requiredProperties: TAllowedProperties; requiredPseudos: TAllowedPseudos; } = never, > = ReturnType< typeof XCSSProp<TAllowedProperties, TAllowedPseudos, TRequiredProperties> >; ``` Then this becomes a bit easier of a type to understand: ```diff -export const Component = ({ xcss }: { xcss?: ReturnType<typeof XCSSProp<…>> }) => +export const Component = ({ xcss }: { xcss?: StrictXCSSProp<…> }) => <div className={xcss} /> ``` Particularly when contrasted against the non-createStrictAPI `XCSSProp` type, which is different. * Change `XCSSAllProperties` (which we document for usage) to be our `StrictCSSProperties` as it removes some edge-cases.
1 parent c252398 commit 5dca5c5

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed
 

‎.changeset/gorgeous-melons-sniff.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compiled/react': patch
3+
---
4+
5+
Export `CSSPseudos, CSSProperties, StrictCSSProperties` types for a strict `XCSSProp` implementation.

‎packages/react/src/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import { createElement } from 'react';
22

33
import type { CompiledJSX } from './jsx/jsx-local-namespace';
4-
import type { CssFunction, CSSProps, CssType } from './types';
54

6-
export type { CSSProps, CssFunction, CssType };
7-
8-
export { keyframes } from './keyframes';
9-
export { styled } from './styled';
105
export { ClassNames } from './class-names';
6+
export { createStrictAPI } from './create-strict-api';
117
export { default as css } from './css';
128
export { default as cssMap } from './css-map';
13-
export { createStrictAPI } from './create-strict-api';
9+
export { keyframes } from './keyframes';
10+
export { styled } from './styled';
11+
export type {
12+
CSSProperties,
13+
CSSProps,
14+
CSSPseudos,
15+
CssFunction,
16+
CssType,
17+
StrictCSSProperties,
18+
} from './types';
1419
export { type XCSSAllProperties, type XCSSAllPseudos, type XCSSProp, cx } from './xcss-prop';
1520

1621
// Pass through the (classic) jsx runtime.

‎packages/react/src/xcss-prop/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type * as CSS from 'csstype';
22

33
import { ac } from '../runtime';
4-
import type { CSSPseudos, CSSProperties } from '../types';
4+
import type { CSSPseudos, CSSProperties, StrictCSSProperties } from '../types';
55

66
type MarkAsRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
77

@@ -64,7 +64,7 @@ export type CompiledStyles<TObject> = {
6464
* Use in conjunction with {@link XCSSProp} to allow all properties to be given to
6565
* your component.
6666
*/
67-
export type XCSSAllProperties = keyof CSSProperties;
67+
export type XCSSAllProperties = keyof StrictCSSProperties;
6868

6969
/**
7070
* Please think twice before using this type, you're better off declaring explicitly

0 commit comments

Comments
 (0)
Please sign in to comment.