From 2ee38183e343d5051b8a3c24af5981e69b2958c1 Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Fri, 8 Sep 2023 12:10:00 -0400 Subject: [PATCH] keep PropTypes in sync with TS changes --- .../scripts/testModuleAugmentation.js | 65 +++++++++++++++++++ .../src/FormControl/FormControl.d.ts | 7 +- .../mui-material/src/FormLabel/FormLabel.d.ts | 6 +- .../mui-material/src/TextField/TextField.js | 2 +- 4 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 packages/mui-material/scripts/testModuleAugmentation.js diff --git a/packages/mui-material/scripts/testModuleAugmentation.js b/packages/mui-material/scripts/testModuleAugmentation.js new file mode 100644 index 00000000000000..8b23912c5030d2 --- /dev/null +++ b/packages/mui-material/scripts/testModuleAugmentation.js @@ -0,0 +1,65 @@ +const childProcess = require('child_process'); +const path = require('path'); +const { chunk } = require('lodash'); +const glob = require('fast-glob'); +const { promisify } = require('util'); + +const exec = promisify(childProcess.exec); +const packageRoot = path.resolve(__dirname, '../'); + +async function test(tsconfigPath) { + try { + await exec(['yarn', 'tsc', '--project', tsconfigPath].join(' '), { cwd: packageRoot }); + } catch (error) { + if (error.stdout !== undefined) { + // `exec` error + throw new Error(`exit code ${error.code}: ${error.stdout}`); + } + // Unknown error + throw error; + } +} + +/** + * Tests various module augmentation scenarios. + * We can't run them with a single `tsc` run since these apply globally. + * Running them all would mean they're not isolated. + * Each test case represents a section in our docs. + * + * We're not using mocha since mocha is used for runtime tests. + * This script also allows us to test in parallel which we can't do with our mocha tests. + */ +async function main() { + const tsconfigPaths = await glob('test/typescript/moduleAugmentation/*.tsconfig.json', { + absolute: true, + cwd: packageRoot, + }); + // Need to process in chunks or we might run out-of-memory + // approximate yarn lerna --concurrency 7 + const tsconfigPathsChunks = chunk(tsconfigPaths, 7); + + // eslint-disable-next-line no-restricted-syntax + for await (const tsconfigPathsChunk of tsconfigPathsChunks) { + await Promise.all( + tsconfigPathsChunk.map(async (tsconfigPath) => { + await test(tsconfigPath).then( + () => { + // eslint-disable-next-line no-console -- test runner feedback + console.log(`PASS ${path.relative(process.cwd(), tsconfigPath)}`); + }, + (error) => { + // don't bail but log the error + console.error(`FAIL ${path.relative(process.cwd(), tsconfigPath)}\n ${error}`); + // and mark the test as failed + process.exitCode = 1; + }, + ); + }), + ); + } +} + +main().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/packages/mui-material/src/FormControl/FormControl.d.ts b/packages/mui-material/src/FormControl/FormControl.d.ts index ad3e453b33cd96..24ba4ce8dba4be 100644 --- a/packages/mui-material/src/FormControl/FormControl.d.ts +++ b/packages/mui-material/src/FormControl/FormControl.d.ts @@ -8,8 +8,11 @@ import { FormControlClasses } from './formControlClasses'; export interface FormControlPropsSizeOverrides {} export interface FormControlPropsColorOverrides {} -export interface FormControlOwnProps - extends Pick, 'children'> { +export interface FormControlOwnProps { + /** + * The content of the component. + */ + children?: React.HTMLAttributes['children']; /** * Override or extend the styles applied to the component. */ diff --git a/packages/mui-material/src/FormLabel/FormLabel.d.ts b/packages/mui-material/src/FormLabel/FormLabel.d.ts index 560322a45de5de..16ee676a92892f 100644 --- a/packages/mui-material/src/FormLabel/FormLabel.d.ts +++ b/packages/mui-material/src/FormLabel/FormLabel.d.ts @@ -12,7 +12,11 @@ export interface FormLabelPropsColorOverrides {} */ export type FormLabelBaseProps = React.LabelHTMLAttributes; -export interface FormLabelOwnProps extends Pick { +export interface FormLabelOwnProps { + /** + * The content of the component. + */ + children?: React.LabelHTMLAttributes['children']; /** * Override or extend the styles applied to the component. */ diff --git a/packages/mui-material/src/TextField/TextField.js b/packages/mui-material/src/TextField/TextField.js index df210682e3412c..86dc50c9519040 100644 --- a/packages/mui-material/src/TextField/TextField.js +++ b/packages/mui-material/src/TextField/TextField.js @@ -236,7 +236,7 @@ TextField.propTypes /* remove-proptypes */ = { */ autoFocus: PropTypes.bool, /** - * @ignore + * The content of the component. */ children: PropTypes.node, /**