Open
Description
Steps to reproduce
Link to live example: https://codesandbox.io/p/sandbox/infallible-nightingale-8h29cd?file=%2Fsrc%2FDemo.tsx%3A35%2C3
Steps:
- In Demo.tsx line 50, apiRef has type React.MutableRefObject<Partial<{}> | undefined>
Current behavior
Typescript compilation fails with errors: "Property 'getItem' does not exist on type 'Partial<{}>'.", "Property 'getItemDOMElement' does not exist on type 'Partial<{}>'.". This is the sample use case of getItem in code: "const item = apiRef.current!.getItem(itemId);". This happens also when apiRef.current is explicitly checked for being defined (e.g. const item = apiRef.current ? apiRef.current!.getItem(itemId) : null;).
Expected behavior
apiRef is properly typed, and there are no errors during compilation.
Context
No response
Your environment
npx @mui/envinfo
System:
OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: Not Found
Browsers:
Chrome: Not Found
npmPackages:
@emotion/react: ^11.13.0 => 11.13.0
@emotion/styled: ^11.13.0 => 11.13.0
@mui/base: 5.0.0-alpha.122
@mui/core-downloads-tracker: 5.16.7
@mui/icons-material: ^5.11.11 => 5.11.16
@mui/material: ^5.16.7 => 5.16.7
@mui/private-theming: 5.16.6
@mui/styled-engine: 5.16.6
@mui/system: 5.16.7
@mui/types: 7.2.15
@mui/utils: ^5.15.7 => 5.16.6
@mui/x-data-grid: latest => 6.9.0
@mui/x-date-pickers: ^6.3.0 => 6.3.0
@mui/x-internals: 7.12.0
@mui/x-tree-view: ^7.12.1 => 7.12.1
@types/react: ^18.0.28 => 18.0.28
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
typescript: ^4.9.5 => 4.9.5
tsconfig
{
"compilerOptions": {
"strict": true,
"allowUnreachableCode": false,
"exactOptionalPropertyTypes": false,
"noImplicitReturns": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"noPropertyAccessFromIndexSignature": true,
"skipLibCheck": true,
"allowJs": true,
"baseUrl": "src",
"paths": {
"@/*": ["./*"]
},
"jsx": "preserve",
"lib": ["DOM", "DOM.Iterable", "ESNext", "WebWorker"],
"module": "ESNext",
"moduleResolution": "Node",
"noEmit": true,
"preserveConstEnums": true,
"resolveJsonModule": true,
"target": "ESNext",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,
"incremental": true,
"types": ["node", "jest", "@testing-library/jest-dom"],
"plugins": [{ "name": "typescript-plugin-css-modules" }]
},
"include": ["**/*.ts", "**/*.tsx", "next.config.js", "next-env.d.ts", "global.d.ts"],
"exclude": ["node_modules"]
}
Search keywords: useTreeViewApiRef, apiRef, getItem