Skip to content

Commit

Permalink
[core] Fix propTypes generation for optional any props (#31141)
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw committed Feb 24, 2022
1 parent 0b8778b commit 7945b46
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/popper-unstyled.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"modifiers": {
"type": {
"name": "arrayOf",
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name?: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
}
},
"placement": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api-docs/popper.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"modifiers": {
"type": {
"name": "arrayOf",
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name?: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
}
},
"placement": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/base/api/popper-unstyled.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"modifiers": {
"type": {
"name": "arrayOf",
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name?: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
}
},
"placement": {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/material/api/popper.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"modifiers": {
"type": {
"name": "arrayOf",
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
"description": "Array&lt;{ data?: object, effect?: func, enabled?: bool, fn?: func, name?: any, options?: object, phase?: 'afterMain'<br>&#124;&nbsp;'afterRead'<br>&#124;&nbsp;'afterWrite'<br>&#124;&nbsp;'beforeMain'<br>&#124;&nbsp;'beforeRead'<br>&#124;&nbsp;'beforeWrite'<br>&#124;&nbsp;'main'<br>&#124;&nbsp;'read'<br>&#124;&nbsp;'write', requires?: Array&lt;string&gt;, requiresIfExists?: Array&lt;string&gt; }&gt;"
}
},
"placement": {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/PopperUnstyled/PopperUnstyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ PopperUnstyled.propTypes /* remove-proptypes */ = {
effect: PropTypes.func,
enabled: PropTypes.bool,
fn: PropTypes.func,
name: PropTypes.any.isRequired,
name: PropTypes.any,
options: PropTypes.object,
phase: PropTypes.oneOf([
'afterMain',
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Popper/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Popper.propTypes /* remove-proptypes */ = {
effect: PropTypes.func,
enabled: PropTypes.bool,
fn: PropTypes.func,
name: PropTypes.any.isRequired,
name: PropTypes.any,
options: PropTypes.object,
phase: PropTypes.oneOf([
'afterMain',
Expand Down
19 changes: 10 additions & 9 deletions packages/typescript-to-proptypes/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,16 @@ export function parseFromProgram(
declaration &&
ts.isPropertySignature(declaration)
) {
parsedType = declaration.questionToken
? t.createUnionType({
jsDoc: getDocumentation(symbol),
types: [
t.createUndefinedType({ jsDoc: undefined }),
t.createAnyType({ jsDoc: undefined }),
],
})
: t.createAnyType({ jsDoc: getDocumentation(symbol) });
parsedType =
symbol.flags & ts.SymbolFlags.Optional
? t.createUnionType({
jsDoc: getDocumentation(symbol),
types: [
t.createUndefinedType({ jsDoc: undefined }),
t.createAnyType({ jsDoc: undefined }),
],
})
: t.createAnyType({ jsDoc: getDocumentation(symbol) });
} else {
parsedType = checkType(type, location, typeStack, symbol.getName());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type Props = {
foo: any;
};

export default function Foo(props: Partial<Props>): JSX.Element;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Foo.propTypes = {
foo: PropTypes.any,
};

0 comments on commit 7945b46

Please sign in to comment.