From c6f464d960b355ee750fd2a251484aeaabac09da Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 8 Mar 2025 07:24:33 +0100 Subject: [PATCH 1/7] Fix type resolution for @mui/types --- packages/mui-types/package.json | 9 +- .../OverridableComponentAugmentation.ts | 0 packages/mui-types/src/index.d.ts | 101 ++++++++++++++++++ packages/mui-types/{ => src}/index.spec.ts | 2 +- .../mui-types/{index.d.ts => src/index.ts} | 4 +- packages/mui-types/tsconfig.build.json | 15 +++ packages/mui-types/tsconfig.json | 2 +- packages/mui-utils/tsconfig.build.json | 3 +- pnpm-lock.yaml | 4 + scripts/build.mjs | 2 +- tsconfig.json | 2 +- 11 files changed, 137 insertions(+), 7 deletions(-) rename packages/mui-types/{ => src}/OverridableComponentAugmentation.ts (100%) create mode 100644 packages/mui-types/src/index.d.ts rename packages/mui-types/{ => src}/index.spec.ts (77%) rename packages/mui-types/{index.d.ts => src/index.ts} (97%) create mode 100644 packages/mui-types/tsconfig.build.json diff --git a/packages/mui-types/package.json b/packages/mui-types/package.json index c12b91b9c8d9b6..4073cd9676d5ab 100644 --- a/packages/mui-types/package.json +++ b/packages/mui-types/package.json @@ -26,7 +26,11 @@ }, "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", @@ -38,6 +42,9 @@ "access": "public", "directory": "build" }, + "dependencies": { + "@babel/runtime": "^7.26.9" + }, "devDependencies": { "@mui/types": "workspace:*", "@types/react": "^19.0.10" diff --git a/packages/mui-types/OverridableComponentAugmentation.ts b/packages/mui-types/src/OverridableComponentAugmentation.ts similarity index 100% rename from packages/mui-types/OverridableComponentAugmentation.ts rename to packages/mui-types/src/OverridableComponentAugmentation.ts diff --git a/packages/mui-types/src/index.d.ts b/packages/mui-types/src/index.d.ts new file mode 100644 index 00000000000000..c247032e4b1acd --- /dev/null +++ b/packages/mui-types/src/index.d.ts @@ -0,0 +1,101 @@ +import * as React from 'react'; +export {}; +/** + * `T extends ConsistentWith` means that where `T` has overlapping properties with + * `U`, their value types do not conflict. + * + * @internal + */ +export type ConsistentWith = { + [P in keyof DecorationTargetProps]: P extends keyof InjectedProps ? InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : InjectedProps[P] : DecorationTargetProps[P]; +}; +/** + * a function that takes {component} and returns a component that passes along + * all the props to {component} except the {InjectedProps} and will accept + * additional {AdditionalProps} + */ +export type PropInjector = , InjectedProps>>>(component: C) => React.JSXElementConstructor>, keyof InjectedProps> & AdditionalProps>; +/** + * Remove properties `K` from `T`. + * Distributive for union types. + * + * @internal + */ +export type DistributiveOmit = T extends any ? Omit : never; +/** + * Generate a set of string literal types with the given default record `T` and + * override record `U`. + * + * If the property value was `true`, the property key will be added to the + * string union. + * + * @internal + */ +export type OverridableStringUnion = GenerateStringUnion, U>>; +/** + * Like `T & U`, but using the value types from `U` where their properties overlap. + * + * @internal + */ +export type Overwrite = DistributiveOmit & U; +type GenerateStringUnion = Extract<{ + [Key in keyof T]: true extends T[Key] ? Key : never; +}[keyof T], string>; +export type IfEquals = (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 ? Y : N; +/** + * Issues a type error if `Expected` is not identical to `Actual`. + * + * `Expected` should be declared when invoking `expectType`. + * `Actual` should almost always we be a `typeof value` statement. + * + * @example `expectType(value)` + * TypeScript issues a type error since `value is not assignable to never`. + * This means `typeof value` is not identical to `number | string` + * @param actual + */ +export declare function expectType(actual: IfEquals): void; +/** + * A component whose root component can be controlled via a `component` prop. + * + * Adjusts valid props based on the type of `component`. + */ +export interface OverridableComponent { + (props: { + /** + * The component used for the root node. + * Either a string to use a HTML element or a component. + */ + component: C; + } & OverrideProps): React.JSX.Element | null; + (props: DefaultComponentProps): React.JSX.Element | null; + propTypes?: any; +} +/** + * Props of the component if `component={Component}` is used. + */ +export type OverrideProps = (BaseProps & DistributiveOmit, keyof BaseProps>); +/** + * Props if `component={Component}` is NOT used. + */ +export type DefaultComponentProps = BaseProps & DistributiveOmit, keyof BaseProps>; +/** + * Props defined on the component. + */ +export type BaseProps = M['props']; +export interface OverridableTypeMap { + props: {}; + defaultComponent: React.ElementType; +} +/** + * Simplifies the display of a type (without modifying it). + * Taken from https://effectivetypescript.com/2022/02/25/gentips-4-display/ + */ +export type Simplify = T extends Function ? T : { + [K in keyof T]: T[K]; +}; +/** + * Changes the properties K from T to required + */ +export type PartiallyRequired = DistributiveOmit & { + [P in K]-?: T[P]; +}; diff --git a/packages/mui-types/index.spec.ts b/packages/mui-types/src/index.spec.ts similarity index 77% rename from packages/mui-types/index.spec.ts rename to packages/mui-types/src/index.spec.ts index 51d82af1ddd5a9..f32d107b882bbe 100644 --- a/packages/mui-types/index.spec.ts +++ b/packages/mui-types/src/index.spec.ts @@ -1,4 +1,4 @@ -import { expectType } from '@mui/types'; +import { expectType } from 'packages/mui-types/src'; function expectTypeTypes() { // it rejects assignability to `any` diff --git a/packages/mui-types/index.d.ts b/packages/mui-types/src/index.ts similarity index 97% rename from packages/mui-types/index.d.ts rename to packages/mui-types/src/index.ts index 7988996932d6be..afdd3f87b160a7 100644 --- a/packages/mui-types/index.d.ts +++ b/packages/mui-types/src/index.ts @@ -84,7 +84,9 @@ export type IfEquals = * This means `typeof value` is not identical to `number | string` * @param actual */ -export function expectType(actual: IfEquals): void; +export declare function expectType( + actual: IfEquals, +): void; /** * A component whose root component can be controlled via a `component` prop. diff --git a/packages/mui-types/tsconfig.build.json b/packages/mui-types/tsconfig.build.json new file mode 100644 index 00000000000000..53b2bcb1e5a7b6 --- /dev/null +++ b/packages/mui-types/tsconfig.build.json @@ -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*"] +} diff --git a/packages/mui-types/tsconfig.json b/packages/mui-types/tsconfig.json index ecd9465fd7fcc8..85ac3b1b0851f7 100644 --- a/packages/mui-types/tsconfig.json +++ b/packages/mui-types/tsconfig.json @@ -1,4 +1,4 @@ { "extends": "../../tsconfig.json", - "exclude": ["OverridableComponentAugmentation.ts"] + "exclude": ["src/OverridableComponentAugmentation.ts"] } diff --git a/packages/mui-utils/tsconfig.build.json b/packages/mui-utils/tsconfig.build.json index 26edb3c2b1ea91..915404fe310d87 100644 --- a/packages/mui-utils/tsconfig.build.json +++ b/packages/mui-utils/tsconfig.build.json @@ -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" }] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 45ba9d229d724a..dca9b7a51b97e0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2192,6 +2192,10 @@ importers: publishDirectory: build packages/mui-types: + dependencies: + '@babel/runtime': + specifier: ^7.26.9 + version: 7.26.9 devDependencies: '@mui/types': specifier: workspace:* diff --git a/scripts/build.mjs b/scripts/build.mjs index 02c52df809844d..fba47295152e5a 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -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`.', diff --git a/tsconfig.json b/tsconfig.json index dc74ceeb41d51b..bd50b0c6c7e3b1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"], From 274565ea91d063350434697c45b7a4220fbf3334 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 8 Mar 2025 07:29:50 +0100 Subject: [PATCH 2/7] prettier --- packages/mui-types/src/index.d.ts | 78 +++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/packages/mui-types/src/index.d.ts b/packages/mui-types/src/index.d.ts index c247032e4b1acd..195ac0f52f9a49 100644 --- a/packages/mui-types/src/index.d.ts +++ b/packages/mui-types/src/index.d.ts @@ -7,14 +7,28 @@ export {}; * @internal */ export type ConsistentWith = { - [P in keyof DecorationTargetProps]: P extends keyof InjectedProps ? InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : InjectedProps[P] : DecorationTargetProps[P]; + [P in keyof DecorationTargetProps]: P extends keyof InjectedProps + ? InjectedProps[P] extends DecorationTargetProps[P] + ? DecorationTargetProps[P] + : InjectedProps[P] + : DecorationTargetProps[P]; }; /** * a function that takes {component} and returns a component that passes along * all the props to {component} except the {InjectedProps} and will accept * additional {AdditionalProps} */ -export type PropInjector = , InjectedProps>>>(component: C) => React.JSXElementConstructor>, keyof InjectedProps> & AdditionalProps>; +export type PropInjector = < + C extends React.JSXElementConstructor, InjectedProps>>, +>( + component: C, +) => React.JSXElementConstructor< + DistributiveOmit< + React.JSX.LibraryManagedAttributes>, + keyof InjectedProps + > & + AdditionalProps +>; /** * Remove properties `K` from `T`. * Distributive for union types. @@ -31,17 +45,23 @@ export type DistributiveOmit = T extends any ? Omit = GenerateStringUnion, U>>; +export type OverridableStringUnion = GenerateStringUnion< + Overwrite, U> +>; /** * Like `T & U`, but using the value types from `U` where their properties overlap. * * @internal */ export type Overwrite = DistributiveOmit & U; -type GenerateStringUnion = Extract<{ +type GenerateStringUnion = Extract< + { [Key in keyof T]: true extends T[Key] ? Key : never; -}[keyof T], string>; -export type IfEquals = (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 ? Y : N; + }[keyof T], + string +>; +export type IfEquals = + (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 ? Y : N; /** * Issues a type error if `Expected` is not identical to `Actual`. * @@ -53,49 +73,59 @@ export type IfEquals = (() => G extends T ? 1 : * This means `typeof value` is not identical to `number | string` * @param actual */ -export declare function expectType(actual: IfEquals): void; +export declare function expectType( + actual: IfEquals, +): void; /** * A component whose root component can be controlled via a `component` prop. * * Adjusts valid props based on the type of `component`. */ export interface OverridableComponent { - (props: { - /** - * The component used for the root node. - * Either a string to use a HTML element or a component. - */ - component: C; - } & OverrideProps): React.JSX.Element | null; - (props: DefaultComponentProps): React.JSX.Element | null; - propTypes?: any; + ( + props: { + /** + * The component used for the root node. + * Either a string to use a HTML element or a component. + */ + component: C; + } & OverrideProps, + ): React.JSX.Element | null; + (props: DefaultComponentProps): React.JSX.Element | null; + propTypes?: any; } /** * Props of the component if `component={Component}` is used. */ -export type OverrideProps = (BaseProps & DistributiveOmit, keyof BaseProps>); +export type OverrideProps< + M extends OverridableTypeMap, + C extends React.ElementType, +> = BaseProps & DistributiveOmit, keyof BaseProps>; /** * Props if `component={Component}` is NOT used. */ -export type DefaultComponentProps = BaseProps & DistributiveOmit, keyof BaseProps>; +export type DefaultComponentProps = BaseProps & + DistributiveOmit, keyof BaseProps>; /** * Props defined on the component. */ export type BaseProps = M['props']; export interface OverridableTypeMap { - props: {}; - defaultComponent: React.ElementType; + props: {}; + defaultComponent: React.ElementType; } /** * Simplifies the display of a type (without modifying it). * Taken from https://effectivetypescript.com/2022/02/25/gentips-4-display/ */ -export type Simplify = T extends Function ? T : { - [K in keyof T]: T[K]; -}; +export type Simplify = T extends Function + ? T + : { + [K in keyof T]: T[K]; + }; /** * Changes the properties K from T to required */ export type PartiallyRequired = DistributiveOmit & { - [P in K]-?: T[P]; + [P in K]-?: T[P]; }; From a6ceb0a3e2f36c9d80d1333178e6f0ff312fa56e Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 8 Mar 2025 07:31:18 +0100 Subject: [PATCH 3/7] Delete index.d.ts --- packages/mui-types/src/index.d.ts | 131 ------------------------------ 1 file changed, 131 deletions(-) delete mode 100644 packages/mui-types/src/index.d.ts diff --git a/packages/mui-types/src/index.d.ts b/packages/mui-types/src/index.d.ts deleted file mode 100644 index 195ac0f52f9a49..00000000000000 --- a/packages/mui-types/src/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -import * as React from 'react'; -export {}; -/** - * `T extends ConsistentWith` means that where `T` has overlapping properties with - * `U`, their value types do not conflict. - * - * @internal - */ -export type ConsistentWith = { - [P in keyof DecorationTargetProps]: P extends keyof InjectedProps - ? InjectedProps[P] extends DecorationTargetProps[P] - ? DecorationTargetProps[P] - : InjectedProps[P] - : DecorationTargetProps[P]; -}; -/** - * a function that takes {component} and returns a component that passes along - * all the props to {component} except the {InjectedProps} and will accept - * additional {AdditionalProps} - */ -export type PropInjector = < - C extends React.JSXElementConstructor, InjectedProps>>, ->( - component: C, -) => React.JSXElementConstructor< - DistributiveOmit< - React.JSX.LibraryManagedAttributes>, - keyof InjectedProps - > & - AdditionalProps ->; -/** - * Remove properties `K` from `T`. - * Distributive for union types. - * - * @internal - */ -export type DistributiveOmit = T extends any ? Omit : never; -/** - * Generate a set of string literal types with the given default record `T` and - * override record `U`. - * - * If the property value was `true`, the property key will be added to the - * string union. - * - * @internal - */ -export type OverridableStringUnion = GenerateStringUnion< - Overwrite, U> ->; -/** - * Like `T & U`, but using the value types from `U` where their properties overlap. - * - * @internal - */ -export type Overwrite = DistributiveOmit & U; -type GenerateStringUnion = Extract< - { - [Key in keyof T]: true extends T[Key] ? Key : never; - }[keyof T], - string ->; -export type IfEquals = - (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 ? Y : N; -/** - * Issues a type error if `Expected` is not identical to `Actual`. - * - * `Expected` should be declared when invoking `expectType`. - * `Actual` should almost always we be a `typeof value` statement. - * - * @example `expectType(value)` - * TypeScript issues a type error since `value is not assignable to never`. - * This means `typeof value` is not identical to `number | string` - * @param actual - */ -export declare function expectType( - actual: IfEquals, -): void; -/** - * A component whose root component can be controlled via a `component` prop. - * - * Adjusts valid props based on the type of `component`. - */ -export interface OverridableComponent { - ( - props: { - /** - * The component used for the root node. - * Either a string to use a HTML element or a component. - */ - component: C; - } & OverrideProps, - ): React.JSX.Element | null; - (props: DefaultComponentProps): React.JSX.Element | null; - propTypes?: any; -} -/** - * Props of the component if `component={Component}` is used. - */ -export type OverrideProps< - M extends OverridableTypeMap, - C extends React.ElementType, -> = BaseProps & DistributiveOmit, keyof BaseProps>; -/** - * Props if `component={Component}` is NOT used. - */ -export type DefaultComponentProps = BaseProps & - DistributiveOmit, keyof BaseProps>; -/** - * Props defined on the component. - */ -export type BaseProps = M['props']; -export interface OverridableTypeMap { - props: {}; - defaultComponent: React.ElementType; -} -/** - * Simplifies the display of a type (without modifying it). - * Taken from https://effectivetypescript.com/2022/02/25/gentips-4-display/ - */ -export type Simplify = T extends Function - ? T - : { - [K in keyof T]: T[K]; - }; -/** - * Changes the properties K from T to required - */ -export type PartiallyRequired = DistributiveOmit & { - [P in K]-?: T[P]; -}; From 2fb5b4617e4f8eaf9630e05d34dab9c29bff372d Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 8 Mar 2025 07:54:32 +0100 Subject: [PATCH 4/7] Trigger Build From 610d5f20e283e4d2b09d49c614df09e75b0a7e98 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 8 Mar 2025 08:33:16 +0100 Subject: [PATCH 5/7] Update package.json --- packages/mui-types/package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/mui-types/package.json b/packages/mui-types/package.json index 4073cd9676d5ab..bfd1b086089fc8 100644 --- a/packages/mui-types/package.json +++ b/packages/mui-types/package.json @@ -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", From b33e705a8446d97ce5cdd379ef9bf1bb8027ee3b Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 8 Mar 2025 08:39:04 +0100 Subject: [PATCH 6/7] Update package.json --- packages/mui-types/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/mui-types/package.json b/packages/mui-types/package.json index bfd1b086089fc8..6a8bcfb0dd7c8d 100644 --- a/packages/mui-types/package.json +++ b/packages/mui-types/package.json @@ -31,7 +31,8 @@ "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": { From c6c91624edb10f1308951b74782a77fb99283b38 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 8 Mar 2025 11:24:04 +0100 Subject: [PATCH 7/7] Update tsconfig.json --- packages/mui-types/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mui-types/tsconfig.json b/packages/mui-types/tsconfig.json index 85ac3b1b0851f7..88bd1eed68395f 100644 --- a/packages/mui-types/tsconfig.json +++ b/packages/mui-types/tsconfig.json @@ -1,4 +1,5 @@ { "extends": "../../tsconfig.json", + "include": ["src/**/*", "test/**/*"], "exclude": ["src/OverridableComponentAugmentation.ts"] }