Skip to content

Commit

Permalink
[Slider][material] Fix type dependency on @types/prop-types (#37853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Methuselah96 committed Jul 12, 2023
1 parent 47790b6 commit 0a11783
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
10 changes: 0 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,6 @@ jobs:
yarn workspace @mui/material typescript:module-augmentation
yarn workspace @mui/base typescript:module-augmentation
yarn workspace @mui/joy typescript:module-augmentation
- restore_cache:
name: Restore generated declaration files
keys:
# #default-branch-switch
# We assume that the target branch is `master` and that declaration files are persisted in commit order.
# "If there are multiple matches, the most recently generated cache will be used."
- typescript-declaration-files-master

- run:
name: Diff declaration files
command: |
Expand All @@ -286,7 +277,6 @@ jobs:
git add -f packages/mui-utils/build || echo '/utils declarations do not exist'
yarn lerna run build:types
git --no-pager diff
- run:
name: Any defect declaration files?
command: node scripts/testBuiltTypes.mjs
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material-next/src/Button/Ripple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ Ripple.propTypes = {
* exit delay
*/
timeout: PropTypes.number.isRequired,
};
} as any;

export default Ripple;
export default Ripple as (props: RippleProps) => JSX.Element;
2 changes: 1 addition & 1 deletion packages/mui-material-next/src/Button/TouchRipple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,6 @@ TouchRipple.propTypes = {
* @ignore
*/
className: PropTypes.string,
};
} as any;

export default TouchRipple;
14 changes: 7 additions & 7 deletions packages/mui-material-next/src/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ SliderRoot.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
};
} as any;

export { SliderRoot };

Expand Down Expand Up @@ -145,7 +145,7 @@ SliderRail.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
};
} as any;

export { SliderRail };

Expand Down Expand Up @@ -193,7 +193,7 @@ SliderTrack.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
};
} as any;

export { SliderTrack };

Expand Down Expand Up @@ -294,7 +294,7 @@ SliderThumb.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
};
} as any;

export { SliderThumb };

Expand Down Expand Up @@ -391,7 +391,7 @@ SliderValueLabel.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.element,
};
} as any;

export { SliderValueLabel };

Expand Down Expand Up @@ -438,7 +438,7 @@ SliderMark.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
};
} as any;

export { SliderMark };

Expand Down Expand Up @@ -490,7 +490,7 @@ SliderMarkLabel.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
};
} as any;

export { SliderMarkLabel };

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Slider/SliderValueLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ SliderValueLabel.propTypes = {
children: PropTypes.element.isRequired,
className: PropTypes.string,
value: PropTypes.node,
};
} as any;
16 changes: 16 additions & 0 deletions scripts/buildTypes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ async function main() {

async function rewriteImportPaths(declarationFile) {
const code = await fse.readFile(declarationFile, { encoding: 'utf8' });
const basename = path.basename(declarationFile);

if (
// Only consider React components
basename[0] === basename[0].toUpperCase() &&
code.indexOf("import PropTypes from 'prop-types';") !== -1
) {
throw new Error(
[
`${declarationFile} imports from 'prop-types', this is wrong.`,
"It's likely missing a cast to any on the propTypes declaration:",
'ComponentName.propTypes = { /* prop */ } as any;',
].join('\n'),
);
}

let fixedCode = code;
const changes = [];

Expand Down

0 comments on commit 0a11783

Please sign in to comment.