[code-infra] Convert @mui/styled-engine to TypeScript#48544
Conversation
0eb81ef to
e2dad6f
Compare
e2dad6f to
e84b914
Compare
Deploy previewhttps://deploy-preview-48544--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
56eb2a4 to
c379788
Compare
There was a problem hiding this comment.
Pull request overview
Converts @mui/styled-engine from handwritten .js + .d.ts sources to “true TypeScript”, emitting declarations via tsc (with Babel still responsible for JS transpilation), and wires it into project references for downstream typechecking (notably @mui/system).
Changes:
- Replaces source files in
@mui/styled-enginewith.ts/.tsxequivalents and adds declaration-onlytsconfig.build.json. - Updates build/typecheck wiring (package build script, exports, and
@mui/systemTS project references). - Adds/adjusts unit tests to cover dev warning behavior and TS typing changes.
Reviewed changes
Copilot reviewed 14 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds @types/prop-types to the lockfile for the TS migration. |
| packages/mui-system/tsconfig.build.json | Adds a project reference to mui-styled-engine so mui-system can typecheck/build against it. |
| packages/mui-styled-engine/tsconfig.json | Updates TS compiler options for the package’s TS sources. |
| packages/mui-styled-engine/tsconfig.build.json | Adds declaration-only TS build config (composite + emitDeclarationOnly). |
| packages/mui-styled-engine/src/StyledEngineProvider/StyledEngineProvider.tsx | Converts provider implementation to TS with explicit props/types and internal stripping. |
| packages/mui-styled-engine/src/StyledEngineProvider/StyledEngineProvider.test.tsx | Updates tests for the new TS typings. |
| packages/mui-styled-engine/src/StyledEngineProvider/StyledEngineProvider.d.ts | Removes handwritten declaration (now emitted by tsc). |
| packages/mui-styled-engine/src/StyledEngineProvider/index.ts | Switches to type-only re-export to avoid exporting internal runtime helpers. |
| packages/mui-styled-engine/src/StyledEngineProvider/index.js | Removes JS source entrypoint (migrated to TS). |
| packages/mui-styled-engine/src/styled.test.ts | Adds tests for dev warnings on incorrect styled() usage. |
| packages/mui-styled-engine/src/index.ts | Migrates main entry to TS and preserves the public type surface. |
| packages/mui-styled-engine/src/index.js | Removes JS source entrypoint (migrated to TS). |
| packages/mui-styled-engine/src/GlobalStyles/index.ts | Adds type-only re-exports for TS sources. |
| packages/mui-styled-engine/src/GlobalStyles/index.d.ts | Removes handwritten declaration entrypoint (now emitted by tsc). |
| packages/mui-styled-engine/src/GlobalStyles/GlobalStyles.tsx | Migrates GlobalStyles implementation to TS. |
| packages/mui-styled-engine/src/GlobalStyles/GlobalStyles.test.tsx | Adjusts tests for TS typing (annotates theme arg). |
| packages/mui-styled-engine/src/GlobalStyles/GlobalStyles.js | Removes JS source entrypoint (migrated to TS). |
| packages/mui-styled-engine/src/GlobalStyles/GlobalStyles.d.ts | Removes handwritten declaration (now emitted by tsc). |
| packages/mui-styled-engine/package.json | Updates build script, exports to TS sources, and adds @types/prop-types devDependency. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/mui-styled-engine/src/index.ts:6
CreateStyled,StyledComponent, andStyledOptionsare type-only exports from@emotion/styled, but they’re imported as value specifiers. Since this package’s.tsis transpiled via Babel (nottsc), Babel won’t elide type-only named imports unless they useimport type, which can lead to invalid ESM named imports at runtime. Split the import into a value import for the default andimport typefor the types (and similarly makePropsOfa type-only import).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c379788 to
868dc99
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 19 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/mui-styled-engine/src/StyledEngineProvider/StyledEngineProvider.tsx:126
StyledEngineProvideris declared to returnReact.JSX.Element, but whencacheis falsy it returnschildren(aReactNode, potentiallystring | null | undefined | ReactNode[]). Theas React.JSX.Elementcast masks this mismatch.
Consider always returning an element (e.g. wrap children in a fragment when there is no cache) so the implementation matches the return type without a cast.
| } | ||
|
|
||
| return stylesFactory; | ||
| } |
There was a problem hiding this comment.
| } | |
| } as CreateStyled |
Would this work, so that the tag and options does not need any?
There was a problem hiding this comment.
That would be invalid on a function declaration. I guess one could convert to an arrow function, but that wouldn't keep the js byte-compatible.
| export { default } from './StyledEngineProvider'; | ||
| export * from './StyledEngineProvider'; |
There was a problem hiding this comment.
cant these 2 lines just be -
export * from './StyledEngineProvider';There was a problem hiding this comment.
export * from './X' re-exports named exports only, default export is not included in that (according to spec, I'm sure some bundlers do that under some configurations).
Converts
@mui/styled-engineto true TypeScript (same setup as@mui/utils): handwritten.js+.d.tssource replaced with.ts/.tsx, declarations now emitted bytscinstead of copied.index's default export (export default function styled→function styled; export default styled, same runtime), an inherent result of typing the default as emotion'sCreateStyled. Remaining.d.tsdeltas are type-only forms (import type,export type *,declare) that preserve the exported types exactly.@mui/system(the only downstream type consumer) typechecks unchanged; package typecheck and the 19 unit/browser tests pass.Published-tarball diff (base → PR HEAD):
@mui/styled-engine@dd4d4f4vs@868dc99— no significant differences found between the packages.Recording the methodology in a skill for reuse on other packages: #48545