Skip to content

[internals] Make disposable types self-contained without esnext.disposable lib#23164

Merged
JCQuintas merged 1 commit into
mui:masterfrom
JCQuintas:fix/disposable-lib-types
Jul 21, 2026
Merged

[internals] Make disposable types self-contained without esnext.disposable lib#23164
JCQuintas merged 1 commit into
mui:masterfrom
JCQuintas:fix/disposable-lib-types

Conversation

@JCQuintas

Copy link
Copy Markdown
Member

Summary

Fixes #23141

The type declarations shipped by @mui/x-internals/disposable referenced typeof Symbol.dispose, typeof Symbol.asyncDispose, and typeof globalThis.DisposableStack/AsyncDisposableStack. These types only exist when esnext.disposable is part of the consumer's TypeScript lib, so any project type-checking with skipLibCheck: false and a lib without esnext.disposable failed with TS2550/TS7017 in @mui/x-internals and TS2304 in @mui/x-tree-view.

This PR makes the emitted declarations self-contained:

  • disposeSymbol / asyncDisposeSymbol are now typed as unique symbol instead of typeof Symbol.dispose / typeof Symbol.asyncDispose, so they still work as computed member keys (class Foo { [disposeSymbol]() {} }).
  • Disposable, AsyncDisposable, DisposableStack, AsyncDisposableStack (and their constructor interfaces) are declared locally in the module, mirroring the esnext.disposable lib shapes. The DisposableStack const and interface merge, so dependent packages' declaration emit resolves the instance type through @mui/x-internals/disposable rather than the global name.

Runtime behavior is unchanged: the same native-first resolution with the minimal fallback stacks.

Verified against the issue's setup (built packages, "lib": ["es2022", "dom"], skipLibCheck: false): previously 5 errors, now clean. Also clean when the consumer does include esnext.disposable.

@JCQuintas JCQuintas added type: bug It doesn't behave as expected. scope: tree view Changes related to the tree view. This includes TreeView, TreeItem. labels Jul 17, 2026
@JCQuintas JCQuintas self-assigned this Jul 17, 2026
@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23164--material-ui-x.netlify.app/
QR code for https://deploy-preview-23164--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

: (Symbol.for('Symbol.dispose') as typeof Symbol.dispose);
export const disposeSymbol: unique symbol = (
typeof Symbol.dispose === 'symbol' ? Symbol.dispose : Symbol.for('Symbol.dispose')
) as never;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

as never here needed so we can export this as unique symbol.

Technically we could downgrade it to symbol only, but then the [disposeSymbol](): void; below wouldn't be picked up, since ts seems to cleanup symbol keys.

@JCQuintas
JCQuintas marked this pull request as ready for review July 20, 2026 12:04
@JCQuintas
JCQuintas requested a review from romgrk as a code owner July 20, 2026 12:04
@JCQuintas
JCQuintas merged commit b33dbc8 into mui:master Jul 21, 2026
25 checks passed
@JCQuintas
JCQuintas deleted the fix/disposable-lib-types branch July 21, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: tree view Changes related to the tree view. This includes TreeView, TreeItem. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Types depend on esnext.disposable

2 participants