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

Export CSSPseudos, CSSProperties, StrictCSSProperties types for a strict XCSSProp implementation. #1600

Merged
merged 2 commits into from
Dec 22, 2023

Conversation

kylorhall-atlassian
Copy link
Collaborator

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 we want is:

import { createStrictAPI, type CSSPseudos, type StrictCSSProperties, type XCSSAllProperties, type XCSSAllPseudos } from '@compiled/react';

const { XCSSProp, css, cssMap, cx } = createStrictAPI<>();

/** Re-implementing the jsdoc */
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:

-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.


Draft, pending final validation of the idea.

Copy link

changeset-bot bot commented Dec 21, 2023

🦋 Changeset detected

Latest commit: 2c9bf78

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@compiled/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Collaborator

@itsdouges itsdouges left a comment

Choose a reason for hiding this comment

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

LGTM

@itsdouges itsdouges marked this pull request as ready for review December 22, 2023 00:59
…trict `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.
…trictCSSProperties` as it removes some edge-cases.
@kylorhall-atlassian kylorhall-atlassian force-pushed the export-types-for-xcssprops-strict branch from 2a93b6c to 2c9bf78 Compare December 22, 2023 01:01
@itsdouges itsdouges merged commit 5dca5c5 into master Dec 22, 2023
5 checks passed
@itsdouges itsdouges deleted the export-types-for-xcssprops-strict branch December 22, 2023 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants