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

[material-ui][TextField] TypeScript not working #41964

Closed
ArthurNRL opened this issue Apr 18, 2024 · 6 comments
Closed

[material-ui][TextField] TypeScript not working #41964

ArthurNRL opened this issue Apr 18, 2024 · 6 comments
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material support: commercial support: Stack Overflow Please ask the community on Stack Overflow typescript

Comments

@ArthurNRL
Copy link

ArthurNRL commented Apr 18, 2024

The problem in depth

We are migrating some components(Dialogs , forms, etc) to a package so we can share code between projects.
Typescript is basically not working for the TextField component (it's only component showing this behaviour)
I think there's something wrong with the config in this project since it works fine in other project using the same mui packages versions.
Here are some examples of whats happening:
image
image
Basically typescript is not able to evaluate the types of the props. This is blocking me since the ci/cd need the tsc to pass.

# tsconfig.json
{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["dom", "dom.iterable", "esnext"],
    "types": ["vite/client"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "preserveSymlinks": true
  },
  "include": ["src", "index.ts"],
  "references": [{ "path": "./tsconfig.node.json" }]
}
# tsconfig.node.json
{
  "compilerOptions": {
    "composite": true,
    "skipLibCheck": true,
    "module": "ESNext",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts"]
}

# vite.config.ts
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
import checker from "vite-plugin-checker";
import dts from "vite-plugin-dts";
import viteTsconfigPaths from "vite-tsconfig-paths";
import { peerDependencies } from "./package.json";

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    lib: {
      entry: "./index.ts", // Specifies the entry point for building the library.
      name: "wam-core-frontend", // Sets the name of the generated library.
      fileName: `index`,
      formats: ["es"],
    },
    rollupOptions: {
      external: [...Object.keys(peerDependencies)], // Defines external dependencies for Rollup bundling.
    },
    sourcemap: true, // Generates source maps for debugging.
    emptyOutDir: true, // Clears the output directory before building.
  },
  plugins: [
    react(),
    dts(),
    viteTsconfigPaths(),
    checker({
      typescript: true,
    }),
  ],
});

Any help is apreciated

Your environment

System:
OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
Binaries:
Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
pnpm: 8.6.0 - ~/.local/share/pnpm/pnpm
Browsers:
Chrome: Not Found
npmPackages:
@emotion/react: 11.11.3
@emotion/styled: 11.11.0
@mui/icons-material: 5.15.15
@mui/lab: 5.0.0-alpha.163
@mui/material: 5.15.15
@mui/system: 5.15.15
@mui/x-data-grid: 6.19.9
@mui/x-data-grid-pro: 6.19.9
@mui/x-date-pickers: 6.19.6
@mui/x-date-pickers-pro: 6.19.6
@mui/x-tree-view: 7.1.0
@types/react: ^18.2.0 => 18.2.0
react: 18.2.0
react-dom: 18.2.0
typescript: ^5.4.5 => 5.4.5

Search keywords: typescript textfield
Order ID: 48634

@ArthurNRL ArthurNRL added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial labels Apr 18, 2024
@michelengelen michelengelen transferred this issue from mui/mui-x Apr 19, 2024
@michelengelen michelengelen changed the title [question] Typescript Issues with TextField [TextField] Typescript Issues with TextField Apr 19, 2024
@michelengelen michelengelen added the component: text field This is the name of the generic UI component, not the React module! label Apr 19, 2024
@danilo-leal danilo-leal changed the title [TextField] Typescript Issues with TextField [material-ui][TextField] TypeScript not working Apr 19, 2024
@danilo-leal danilo-leal added typescript package: material-ui Specific to @mui/material labels Apr 19, 2024
@ArthurNRL
Copy link
Author

ArthurNRL commented Apr 23, 2024

@mj12albert any ideas would be appreciated

@crmcluckie
Copy link

Can we have an update on the ticket, please?

@stefan-klaes
Copy link

stefan-klaes commented Apr 28, 2024

You could provide the type like this:

onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
    setName(event.target.value);
  }}

Pasted it from the docs

@ArthurNRL
Copy link
Author

Of course I could, the issue is that the rest of the props types are not being evaluated correctly. I can pass anything to any props. This does not ensure type safety

@ZeeshanTamboli
Copy link
Member

I think there's something wrong with the config in this project since it works fine in other project using the same mui packages versions.

I suggest to please ask on StackOverflow.

@ZeeshanTamboli ZeeshanTamboli added the support: Stack Overflow Please ask the community on Stack Overflow label May 14, 2024
Copy link

👋 Thanks for using our open-source projects!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support with Material UI please check out https://mui.com/material-ui/getting-started/support/. Thanks!

If you have a question on Stack Overflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2024
@ZeeshanTamboli ZeeshanTamboli removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material support: commercial support: Stack Overflow Please ask the community on Stack Overflow typescript
Projects
None yet
Development

No branches or pull requests

7 participants