Skip to content
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

[code-infra] Fix type resolution for @mui/types #45513

Merged
merged 7 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions packages/mui-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
"author": "MUI Team",
"description": "Utility types for MUI.",
"types": "./index.d.ts",
"files": [
"index.d.ts",
"OverridableComponentAugmentation.ts"
],
"keywords": [
"react",
"react-component",
Expand All @@ -26,18 +22,26 @@
},
"homepage": "https://github.com/mui/material-ui/tree/master/packages/mui-types",
"scripts": {
"build": "mkdir build && cpy index.d.ts build/ && cpy OverridableComponentAugmentation.ts build/ && pnpm build:copy-files",
"build": "pnpm build:modern && pnpm build:node && pnpm build:stable && pnpm build:types && pnpm build:copy-files",
"build:modern": "node ../../scripts/build.mjs modern",
"build:node": "node ../../scripts/build.mjs node",
"build:stable": "node ../../scripts/build.mjs stable",
"build:types": "tsx ../../scripts/buildTypes.mts",
"build:copy-files": "node ../../scripts/copyFiles.mjs",
"prebuild": "rimraf build",
"release": "pnpm build && pnpm publish",
"test": "echo 'No runtime test. Type tests are run with the `typescript` script.'",
"typescript": "tsc -p tsconfig.json"
"typescript": "tsc -p tsconfig.json",
"attw": "attw --pack ./build --exclude-entrypoints esm modern"
},
"sideEffects": false,
"publishConfig": {
"access": "public",
"directory": "build"
},
"dependencies": {
"@babel/runtime": "^7.26.9"
},
"devDependencies": {
"@mui/types": "workspace:*",
"@types/react": "^19.0.10"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expectType } from '@mui/types';
import { expectType } from 'packages/mui-types/src';

function expectTypeTypes() {
// it rejects assignability to `any`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export type IfEquals<T, U, Y = unknown, N = never> =
* This means `typeof value` is not identical to `number | string`
* @param actual
*/
export function expectType<Expected, Actual>(actual: IfEquals<Actual, Expected, Actual>): void;
export declare function expectType<Expected, Actual>(
actual: IfEquals<Actual, Expected, Actual>,
): void;

/**
* A component whose root component can be controlled via a `component` prop.
Expand Down
15 changes: 15 additions & 0 deletions packages/mui-types/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// This config is for emitting declarations (.d.ts) only
// Actual .ts source files are transpiled via babel
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"noEmit": false,
"emitDeclarationOnly": true,
"outDir": "build/esm",
"rootDir": "./src"
},
"include": ["./src/**/*.ts*"],
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"]
}
3 changes: 2 additions & 1 deletion packages/mui-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "../../tsconfig.json",
"exclude": ["OverridableComponentAugmentation.ts"]
"include": ["src/**/*", "test/**/*"],
"exclude": ["src/OverridableComponentAugmentation.ts"]
}
3 changes: 2 additions & 1 deletion packages/mui-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"types": ["react", "node"]
},
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts*", "src/**/*.spec.ts*"]
"exclude": ["src/**/*.test.ts*", "src/**/*.spec.ts*"],
"references": [{ "path": "../mui-types/tsconfig.build.json" }]
}
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function run(argv) {
const packageJsonPath = path.resolve('./package.json');
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, { encoding: 'utf8' }));

const babelRuntimeVersion = packageJson.dependencies['@babel/runtime'];
const babelRuntimeVersion = packageJson.dependencies?.['@babel/runtime'];
if (!babelRuntimeVersion) {
throw new Error(
'package.json needs to have a dependency on `@babel/runtime` when building with `@babel/plugin-transform-runtime`.',
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@mui/styles/*": ["./packages/mui-styles/src/*"],
"@mui/system": ["./packages/mui-system/src"],
"@mui/system/*": ["./packages/mui-system/src/*"],
"@mui/types": ["./packages/mui-types"],
"@mui/types": ["./packages/mui-types/src"],
"@mui/private-theming": ["./packages/mui-private-theming/src"],
"@mui/private-theming/*": ["./packages/mui-private-theming/src/*"],
"@mui/base": ["./packages/mui-base/src"],
Expand Down