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

Fix styleVariants type when using the map data function #804

Merged
merged 3 commits into from
Sep 5, 2022

Conversation

m7yue
Copy link
Contributor

@m7yue m7yue commented Sep 3, 2022

const vars = createThemeContract({
  info: {
    bgColor: null,
  },
  warn: {
    bgColor: null,
  },
  success: {
    bgColor: null,
  },
  error: {
    bgColor: null,
  }
});

export const staticCardStyles = styleVariants(
  vars,
  ({bgColor}) => [staticCard, { backgroundColor: bgColor }]
);

the error in my components lib is:

Property 'bgColor' does not exist on type 'var(--${string}) | var(--${string}, ${string}) | var(--${string}, ${number}) | MapLeafNodes<{ info: { bgColor: null; }; warn: { bgColor: null; }; success: { bgColor: null; }; error: { bgColor: null; }; }[Key], CSSVarFunction>'.ts(2339)

when i fix the styleVariants's type, it's works well.

const vars = createThemeContract({
  info: {
    bgColor: null,
  },
  warn: {
    bgColor: null,
  },
  success: {
    bgColor: null,
  },
  error: {
    bgColor: null,
  }
});

export declare function styleVariants<Data extends Record<string | number, unknown>, Key extends keyof Data>(
  data: Data,
  mapData: (value: Data[Key], key: Key) => ComplexStyleRule,
  debugId?: string
): Record<keyof Data, string>;

export const staticCardStyles = styleVariants(
  vars,
  ({bgColor}) => [staticCard, { backgroundColor: bgColor }]
);

so, i think it related with typescript.

@m7yue m7yue requested a review from a team September 3, 2022 17:09
@changeset-bot
Copy link

changeset-bot bot commented Sep 3, 2022

🦋 Changeset detected

Latest commit: b7056d6

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

This PR includes changesets to release 8 packages
Name Type
@vanilla-extract/css Patch
@fixtures/features Patch
@fixtures/low-level Patch
@fixtures/recipes Patch
@fixtures/sprinkles Patch
@fixtures/themed Patch
@fixtures/unused-modules Patch
vanilla-extract-example-webpack-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

@mattcompiles
Copy link
Contributor

@m7yue Hey bud, thanks for the PR. We've seen this occur as well so thanks for looking into it.

The formatting is invalid though on your change. Could you run pnpm format and push the changes?

@m7yue
Copy link
Contributor Author

m7yue commented Sep 5, 2022

@m7yue Hey bud, thanks for the PR. We've seen this occur as well so thanks for looking into it.

The formatting is invalid though on your change. Could you run pnpm format and push the changes?

ok, i get it.

Copy link
Contributor

@mattcompiles mattcompiles left a comment

Choose a reason for hiding this comment

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

Thanks for the PR mate 👏

@mattcompiles mattcompiles changed the title fix(styleVariants): styleVariants's type error in mapData's Arrow Fun… Fix styleVariants type when using the map data function Sep 5, 2022
@mattcompiles mattcompiles enabled auto-merge (squash) September 5, 2022 04:27
@mattcompiles mattcompiles merged commit 412962f into vanilla-extract-css:master Sep 5, 2022
@seek-oss-ci seek-oss-ci mentioned this pull request Sep 5, 2022
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