Skip to content

Fix: styled typesafe for tagname, variants #247#252

Merged
github-actions[bot] merged 3 commits intomainfrom
styled-typesafe
Oct 6, 2025
Merged

Fix: styled typesafe for tagname, variants #247#252
github-actions[bot] merged 3 commits intomainfrom
styled-typesafe

Conversation

@black7375
Copy link
Contributor

@black7375 black7375 commented Oct 6, 2025

Description

Type safe implement styled.

Related Issue

Summary by CodeRabbit

  • New Features

    • Enhanced TypeScript support for styled components, including richer generics, improved prop inference, and explicit “as” prop handling.
    • Broader compatibility with intrinsic elements and various component forms, improving developer ergonomics and IntelliSense.
    • New public type exports in CSS and React packages to aid advanced typing scenarios.
  • Chores

    • Updated React package dependencies to include @mincho-js/csstype.
  • Refactor

    • Streamlined and unified the typing model for styled components for greater flexibility and consistency across packages.

Additional context

Checklist

@changeset-bot
Copy link

changeset-bot bot commented Oct 6, 2025

🦋 Changeset detected

Latest commit: bc7dd88

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

This PR includes changesets to release 4 packages
Name Type
@mincho-js/react Patch
@mincho-js/css Patch
react-babel Patch
@mincho-js/vite 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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

Triggered from #252 by @​black7375.

Checking if we can fast forward main (d4cde3f) to styled-typesafe (bc7dd88).

Target branch (main):

commit d4cde3f82fdb590ee7ec7740c8f2d6e886696cc1 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Aug 12 00:00:00 2025 +0900

    Docs: Make the changeset format consistent.

Pull request (styled-typesafe):

commit bc7dd88d744fe292db499108074d2a06c49a2063 (pull_request/styled-typesafe)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Aug 16 00:00:00 2025 +0900

    Refactor: `styled` code order & naming

It is possible to fast forward main (d4cde3f) to styled-typesafe (bc7dd88). If you have write access to the target repository, you can add a comment with /fast-forward to fast forward main to styled-typesafe.

@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

Adds changeset entries for patch releases. Exports new type PropDefinitionOutput from @mincho-js/css (compat.ts and index.ts). Overhauls @mincho-js/react styled typings: introduces ComponentWithAs, intrinsic inference helpers, and revised StyledComponent generics using PropDefinitionOutput and ResolveComplex. Updates react package.json to include @mincho-js/csstype.

Changes

Cohort / File(s) Summary
Changesets
\.changeset/clear-chicken-shout.md, \.changeset/violet-paws-jam.md
Patch release notes: document new styled type export in react and new exported type PropDefinitionOutput in css.
CSS type exports
packages/css/src/compat.ts, packages/css/src/index.ts
Re-export PropDefinitionOutput from ./rules/types.js alongside ResolveComplex; minor formatting (trailing commas).
React typings overhaul
packages/react/src/index.ts
Redefines StyledComponent and styled overloads; adds ComponentWithAs, IntrinsicProps, Infer* helpers; integrates PropDefinitionOutput and updated PatternOptionsToProps/ResolveComplex-based prop computation.
React package manifest
packages/react/package.json
Adds dependency "@mincho-js/csstype": "^3.1.4".

Sequence Diagram(s)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45–75 minutes

Possibly related issues

  • styled makes to type-safe #247 — Introduces/export PropDefinitionOutput and rewrites styled typing with "as" polymorphism and variants, matching this PR’s css exports and react typing updates.

Possibly related PRs

Suggested labels

dependencies

Poem

I twitch my whiskers, types aligned,
New props hop in, precisely defined.
With “as” I bound from tag to tag,
Variants tucked in my satchel bag.
CSS and React, a tidy troupe—
Patch by patch, we loop-de-loop! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description follows the template’s section headings but only provides a one-line summary, leaves the autogenerated summary placeholder unfilled, and does not supply any content in the Additional context or Checklist sections, omitting critical detail about what was changed and why. Please replace the “@coderabbitai summary” placeholder with the actual summary of changes, expand the Description to outline the key modifications, and complete the Additional context and Checklist sections with any relevant information and review points.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly references making the styled utility type-safe for component tags and variants, which matches the core change in the PR, though it includes an issue number and could be slightly rephrased for clarity.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch styled-typesafe

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
.changeset/clear-chicken-shout.md (1)

5-6: Use a heading instead of emphasis (MD036).

Replace bold-without-heading with a proper heading for lint compliance.

-**type**
+### type
.changeset/violet-paws-jam.md (1)

5-6: Prefer heading syntax for consistency (avoid emphasis-as-heading).

Use a heading for the “export” section.

-**export**
+### export
packages/react/src/index.ts (2)

144-154: Avoid overriding precise ref types; drop RefAttributes.

Adding RefAttributes to StyledComponent props eclipses accurate ref inference from ComponentProps/ComponentProps, weakening type-safety.

Preferred: rely on ComponentProps-derived ref, or compute ref from ElementRef.

 export type StyledComponent<
   TProps = Record<string, unknown>,
   Component extends ElementType = ElementType,
   Variants extends VariantGroups | undefined = undefined,
   ToggleVariants extends VariantDefinitions | undefined = undefined,
   Props extends ComplexPropDefinitions<PropTarget> | undefined = undefined
 > = ComponentWithAs<
-  TProps &
-    RefAttributes<unknown> &
-    PatternOptionsToProps<Variants, ToggleVariants, Props>,
+  TProps & PatternOptionsToProps<Variants, ToggleVariants, Props>,
   Component
 >;

Alternatively (if you want an explicit ref in Props), use ElementRef:

  • import ElementRef from react
  • use RefAttributes<ElementRef> instead of unknown.

156-166: Prop resolution shape looks sane; minor nit on unknown widening.

PatternOptionsToProps falls back to unknown via NonNever, which can widen resulting prop types in edge cases. If you prefer stricter fallback, consider Record<never, never> instead of unknown to avoid surfacing “any-like” props.

-type NonNever<T> = [T] extends [never] ? unknown : T;
+type NonNever<T> = [T] extends [never] ? Record<never, never> : T;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4cde3f and bc7dd88.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • .changeset/clear-chicken-shout.md (1 hunks)
  • .changeset/violet-paws-jam.md (1 hunks)
  • packages/css/src/compat.ts (1 hunks)
  • packages/css/src/index.ts (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/index.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-09T13:00:38.449Z
Learnt from: black7375
PR: mincho-js/mincho#113
File: packages/css/src/index.ts:33-33
Timestamp: 2024-10-09T13:00:38.449Z
Learning: `recipe` is properly exported from './rules' in `packages/css/src/rules/index.ts`.

Applied to files:

  • packages/css/src/index.ts
  • packages/css/src/compat.ts
🧬 Code graph analysis (1)
packages/react/src/index.ts (2)
packages/css/src/index.ts (9)
  • RulesVariants (33-33)
  • VariantGroups (35-35)
  • ComplexPropDefinitions (38-38)
  • PropTarget (39-39)
  • PatternOptions (36-36)
  • ResolveComplex (43-43)
  • VariantObjectSelection (42-42)
  • ConditionalVariants (41-41)
  • PropDefinitionOutput (44-44)
packages/react/src/runtime.ts (1)
  • $$styled (17-81)
🪛 markdownlint-cli2 (0.18.1)
.changeset/clear-chicken-shout.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (4)
packages/react/package.json (1)

66-68: Dependency placement looks right; please verify public type usage.

If your generated .d.ts references types from @mincho-js/csstype, keeping it in dependencies is correct. If it’s only used internally and not exposed, it can be a devDependency instead.

packages/css/src/index.ts (1)

43-45: LGTM: new public type export is consistent with usage in React typings.

Exporting PropDefinitionOutput here aligns with the styled typing changes downstream.

packages/css/src/compat.ts (1)

41-43: LGTM: compat surface mirrors main export.

PropDefinitionOutput addition here keeps the compat API in sync with index.ts. Recipe export remains intact. Based on learnings.

packages/react/src/index.ts (1)

104-116: Runtime throw in styled: ensure build-time transform is guaranteed.

styled unconditionally throws at runtime. If a transform (Babel/Vite/Rollup/TS) rewrites styled calls to $$styled, you’re fine; otherwise consumers will crash.

  • Verify the repo includes and documents the required transform.
  • Consider providing a runtime-safe alias (e.g., exporting $$styled as styled while retaining overload typings) if feasible in your architecture.

Would you like guidance on a type-only overload + runtime alias pattern to avoid hard runtime throws in dev builds?

@black7375
Copy link
Contributor Author

/fast-forward

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

Triggered from #252 (comment) by @​black7375.

Trying to fast forward main (d4cde3f) to styled-typesafe (bc7dd88).

Target branch (main):

commit d4cde3f82fdb590ee7ec7740c8f2d6e886696cc1 (HEAD -> main, origin/main)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Tue Aug 12 00:00:00 2025 +0900

    Docs: Make the changeset format consistent.

Pull request (styled-typesafe):

commit bc7dd88d744fe292db499108074d2a06c49a2063 (pull_request/styled-typesafe)
Author: alstjr7375 <alstjr7375@daum.net>
Date:   Sat Aug 16 00:00:00 2025 +0900

    Refactor: `styled` code order & naming

Fast forwarding main (d4cde3f) to styled-typesafe (bc7dd88).

$ git push origin bc7dd88d744fe292db499108074d2a06c49a2063:main
To https://github.com/mincho-js/mincho.git
   d4cde3f..bc7dd88  bc7dd88d744fe292db499108074d2a06c49a2063 -> main

@github-actions github-actions bot merged commit bc7dd88 into main Oct 6, 2025
12 checks passed
@github-actions github-actions bot deleted the styled-typesafe branch October 6, 2025 18:26
@github-actions github-actions bot mentioned this pull request Oct 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant