Skip to content

Migrate the library to TypeScript (#394) - #734

Open
bedrich-schindler wants to merge 1 commit into
masterfrom
task/394
Open

Migrate the library to TypeScript (#394)#734
bedrich-schindler wants to merge 1 commit into
masterfrom
task/394

Conversation

@bedrich-schindler

Copy link
Copy Markdown
Contributor

Convert all components, providers, helpers and the library entry from JSX with prop-types to TypeScript (strict: true) while keeping the runtime behaviour and the public exports unchanged.

  • Every component gets a co-located <Component>.types.ts with its Props type (extending the matching *HTMLAttributes) and the JSDoc descriptions copied from propTypes; context values, provider props and helper types live in .types.ts files too. Shared unions (Color, Priority, Size, Layout, ValidationState, Breakpoint, LabelPosition) live in src/types.
  • defaultProps are replaced by default values in the parameter destructuring (react-docgen reads them for the documentation); propTypes are kept for runtime validation. Plain function components are annotated as React.FunctionComponent so propTypes do not leak into the declarations, and withGlobalProps is generic in props and ref element (never for components that do not forward a ref).
  • Toolchain: TypeScript 7 (@typescript/native) type-checks and emits declarations, TypeScript 6 stays installed as typescript for tools that need the compiler API (typescript-eslint); Babel (@babel/preset-typescript) transpiles for webpack and Jest, which replaces ts-jest and the second Jest config. eslint-plugin-deprecation and eslint-plugin-typescript-sort-keys are replaced by @typescript-eslint/no-deprecated and eslint-plugin-perfectionist because they do not support TypeScript 6.
  • Build emits dist/types/** and bundles them with dts-bundle-generator into the published dist/react-ui.d.ts referenced by types; package contents are defined by a files allowlist instead of .npmignore.
  • Stories use the real component props (StoryProps helper for props the story defaults), npm run typecheck is part of npm run lint, and the contributing rules and docs describe the TypeScript setup.

Closes #394

Convert all components, providers, helpers and the library entry from
JSX with `prop-types` to TypeScript (`strict: true`) while keeping the
runtime behaviour and the public exports unchanged.

* Every component gets a co-located `<Component>.types.ts` with its
  `Props` type (extending the matching `*HTMLAttributes`) and the JSDoc
  descriptions copied from `propTypes`; context values, provider props and
  helper types live in `.types.ts` files too. Shared unions (`Color`,
  `Priority`, `Size`, `Layout`, `ValidationState`, `Breakpoint`,
  `LabelPosition`) live in `src/types`.
* `defaultProps` are replaced by default values in the parameter
  destructuring (react-docgen reads them for the documentation);
  `propTypes` are kept for runtime validation. Plain function components
  are annotated as `React.FunctionComponent` so `propTypes` do not leak
  into the declarations, and `withGlobalProps` is generic in props and
  ref element (`never` for components that do not forward a ref).
* Toolchain: TypeScript 7 (`@typescript/native`) type-checks and emits
  declarations, TypeScript 6 stays installed as `typescript` for tools
  that need the compiler API (typescript-eslint); Babel
  (`@babel/preset-typescript`) transpiles for webpack and Jest, which
  replaces `ts-jest` and the second Jest config. `eslint-plugin-deprecation`
  and `eslint-plugin-typescript-sort-keys` are replaced by
  `@typescript-eslint/no-deprecated` and `eslint-plugin-perfectionist`
  because they do not support TypeScript 6.
* Build emits `dist/types/**` and bundles them with `dts-bundle-generator`
  into the published `dist/react-ui.d.ts` referenced by `types`; package
  contents are defined by a `files` allowlist instead of `.npmignore`.
* Stories use the real component props (`StoryProps` helper for props the
  story defaults), `npm run typecheck` is part of `npm run lint`, and the
  contributing rules and docs describe the TypeScript setup.
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://react-ui-org.github.io/react-ui/pr-preview/pr-734/

Built to branch gh-pages at 2026-08-28 20:24 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@bedrich-schindler

Copy link
Copy Markdown
Contributor Author

@mbohal @adamkudrna, Claude was used to migrate whole RUI from JS to TS, but I check every single file before creating pull request (yes, it took a while).

I would like to point out, that with @mbohal we decided to do necessary steps to convert library to TS. Things like removing prop types is part of React update and can be done after updating docoff.

Unfortunately, it was not possible to split it into multiple files as it would be more messy that doing it in one shot.

@bedrich-schindler

Copy link
Copy Markdown
Contributor Author

One more thing. I did minimum changes to source code. So instead of fixing code, I simply added lint ignore so it is not huge mess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transform codebase to Typescript

1 participant