-
Notifications
You must be signed in to change notification settings - Fork 538
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
[Epic] TypeScript refactor #970
Comments
Status💚 Green ShipsWe removed propTypes from all our components in favor of TypeScript types. BlockersWe’re getting Up Next
|
Status💛 Yellow BlockersThe final step of this TypeScript refactor is to replace our manually maintained type definitions with type definitions generated by TypeScript. However, after testing in Memex, I found that the generated type definitions were causing errors because of the way the I figured out a way to correctly define types for the Here's an example of how our components will need to be updatedimport styled from 'styled-components'
import {COMMON, FLEX, LAYOUT, SystemCommonProps, SystemFlexProps, SystemLayoutProps} from './constants'
import sx, {SxProp} from './sx'
- import {ComponentProps} from './utils/types'
+ import {ForwardRefComponent} from './utils/polymorphic'
+ const defaultElement = 'div'
+ export type BoxProps = SystemCommonProps &
+ SystemFlexProps &
+ SystemLayoutProps &
+ SxProp
+ type BoxComponent = ForwardRefComponent<typeof defaultElement, BoxProps>
+ const Box = styled(defaultElement)<BoxProps>`
- const Box = styled.div<BoxProps>`
${COMMON}
${FLEX}
${LAYOUT}
${sx};
+ ` as BoxComponent
- `
- export type BoxProps = ComponentProps<typeof Box>
export default Box I haven't had time to completely implement this solution because of Primer React theming work. I'll reach out to @VanAnderson to see if he as the bandwidth to take this on. Up Next
|
Status💛 Yellow No updates on TypeScript this week because @VanAnderson and I have been focused on the Primer React theming epic. Up Next
|
Status💛 Yellow No updates on TypeScript this week because @VanAnderson and I have been focused on the Primer React theming epic. I'll have the bandwidth to finish up TypeScript work next week. Up Next
|
4/1 UpdateStatus 💚 ShipsThis week we replaced our hand-written type definitions with type definitions generated by the TypeScript compiler (#1147). This means consumers get more accurate type definitions and maintainers no longer have to manually keep the type definitions in sync with the code! This is the culmination of a quarter-long effort to rewrite Primer React in TypeScript 🎉 (#970). These changes will be included in the next release of Primer React. Up Next
|
The exit criteria has been met 🎉 I'm going to go ahead and close this issue. We can track follow-up tasks in separate issues. |
Objective
Rewrite Primer React components in TypeScript.
📄 TypeScript ADR
📄 TypeScript notes google doc
Team
Tasks
Phase 1: Setup
.ts
and.tsx
files TypeScript refactor #959Phase 2: Migrate
In Review or Done
Phase 3: Clean up
index.d.ts
) Replace index.d.ts with generated type definitions #1147Postponed
¹How to migrate a component to TypeScript
The migration process for each component may vary, but it will likely follow these high-level steps:
1. Change the file extension from
.js
to.tsx
2. Add type annotations to the component file
Here are type annotations for the
Box
component:Most Primer React components will follow a similar pattern. Each component should export a
___Props
type in addition to the default export.3. Change the file extension of tests
👉 See the TypeScript notes google doc for more information on TypeScript migration.
Exit criteria
src
directory of primer/components have been rewritten in TypeScript/cc @philipbremer
The text was updated successfully, but these errors were encountered: