-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
styled
API is removing TS definition from components
#37961
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
Comments
@rishavpandey43 Thanks for reporting this ~ I can reproduce your issue, is there a specific reason you want to use If you are building a design system, the recommended method to do "global" (or design-system-wide) styling is in the theme using style overrides: https://mui.com/material-ui/customization/theme-components/#theme-style-overrides It's also the recommended way to set default props, e.g. globally change all your |
Duplicate of #37551 |
I cannot change all I want to create a TruncatedText component, which will truncate the text passed to it. And this is a basic usage, If someone wants to create a wrapper kind of component but does not want to make the global changes these issues should not come. It's a basic usage while working with any UI libraries. There should be flexibility to work, everyone does not have the same needs/requirements. I hope you understand my point here. Can you suggest any workaround in my case here? I've got the same issue with other components like Below is the component I created -
|
Duplicates
Latest version
Steps to reproduce 🕹
Link to live example:
Steps:
Current behavior 😯
I'm styling my component with the
styled
API provided by Mui and it results in errors in using some of the props likecomponent
. If the component is styled bystyled
API, and props likecomponent="p"
is used it's not being recognised by TS and throws an error in the IDE. But as per functionality, it works fine.Styled Typescript -
Expected behavior 🤔
Even though any components are styled using
styled
API their type definition should not behave differently than the actual one.Below is the screenshot error, I'm getting in my actual file.

You can also check out for live preview - https://hkw82y.csb.app/
Context 🔦
I was creating a Design System and wanted some pre-defined props to be passed after styling the components, like Typography, Button, etc. But whenever I style the components, it loses the TS definition and results in a TS error even though it's correct.
No matter if any component is being styled or not, none of the TS definitions should be lost.
Your environment 🌎
`npx @mui/envinfo`
tconfig configuration
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"declaration": true,
"declarationDir": "types",
"sourceMap": false,
"outDir": "dist",
"strict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"emitDeclarationOnly": true,
"jsx": "react-jsx",
"baseUrl": "src",
"lib": ["ES2021", "dom"],
"rootDir": "src"
},
"include": ["src"],
"exclude": [
"src//*.spec.ts",
"src//.stories.tsx",
"src/**/.cy.tsx",
"src/theme/"
]
}
The text was updated successfully, but these errors were encountered: