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] Improve proptypes-generation #40617

Merged
merged 3 commits into from
Jan 22, 2024

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Jan 15, 2024

Simple reproduction of this issue mui/mui-x#11679

I set two way to define ChartSeries<T> but in bot case I only get one type (not the same depending on the union chosen)

However TypeScript seems to correctly understand the series type and its data type

image

@mui/code-infra Is it a known limitation (do you know where it comes from)? If not, I can investigate a bit further

@mui-bot
Copy link

mui-bot commented Jan 15, 2024

Netlify deploy preview

https://deploy-preview-40617--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 750985d

@danilo-leal danilo-leal added the scope: code-infra Specific to the core-infra product label Jan 15, 2024
@michaldudak
Copy link
Member

I'm not aware of such limitations. But I haven't had much to do with the typescript-to-proptypes package so far.

@alexfauquette alexfauquette marked this pull request as ready for review January 22, 2024 13:08
@@ -125,6 +125,7 @@ function checkType({
if (project.checker.isArrayType(type)) {
// @ts-ignore
const arrayType: ts.Type = project.checker.getElementTypeOfArrayType(type);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -94,7 +96,7 @@ export function createInterfaceType(init: {
}

export function createLiteralType(init: {
value: unknown;
value: string | number | ts.PseudoBigInt;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Type come from observing all the createLiteralType() call

two of them only take string, the last one as this typing for it's input value

}

return type.type;
return getTypeHash(type);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the root cause of the issue. If you do the union of two interfaces, they were erased because their type.type is "InterfaceNode" so only one of the two survive to the _.uniqBy

I created a getTypeHash that generate a hash in a recursive way to support interface, union and array

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a typo, but it looks good overall!

@@ -149,6 +150,13 @@ export function uniqueUnionTypes(node: UnionType): UnionType {
return `${type.type}.${type.instance}`;
}

if (type.type === 'InterfaceNode') {
// Allows union of mulitple interface nodes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Allows union of mulitple interface nodes
// Allows union of multiple interface nodes

@alexfauquette alexfauquette merged commit bf76c08 into mui:master Jan 22, 2024
18 checks passed
@alexfauquette alexfauquette deleted the TDD-proptypes branch January 22, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: code-infra Specific to the core-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants