Migrate the library to TypeScript (#394) - #734
Open
bedrich-schindler wants to merge 1 commit into
Open
Conversation
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.
Contributor
|
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. |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Convert all components, providers, helpers and the library entry from JSX with
prop-typesto TypeScript (strict: true) while keeping the runtime behaviour and the public exports unchanged.<Component>.types.tswith itsPropstype (extending the matching*HTMLAttributes) and the JSDoc descriptions copied frompropTypes; context values, provider props and helper types live in.types.tsfiles too. Shared unions (Color,Priority,Size,Layout,ValidationState,Breakpoint,LabelPosition) live insrc/types.defaultPropsare replaced by default values in the parameter destructuring (react-docgen reads them for the documentation);propTypesare kept for runtime validation. Plain function components are annotated asReact.FunctionComponentsopropTypesdo not leak into the declarations, andwithGlobalPropsis generic in props and ref element (neverfor components that do not forward a ref).@typescript/native) type-checks and emits declarations, TypeScript 6 stays installed astypescriptfor tools that need the compiler API (typescript-eslint); Babel (@babel/preset-typescript) transpiles for webpack and Jest, which replacests-jestand the second Jest config.eslint-plugin-deprecationandeslint-plugin-typescript-sort-keysare replaced by@typescript-eslint/no-deprecatedandeslint-plugin-perfectionistbecause they do not support TypeScript 6.dist/types/**and bundles them withdts-bundle-generatorinto the publisheddist/react-ui.d.tsreferenced bytypes; package contents are defined by afilesallowlist instead of.npmignore.StoryPropshelper for props the story defaults),npm run typecheckis part ofnpm run lint, and the contributing rules and docs describe the TypeScript setup.Closes #394