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

mobx 6.7.0 leaks @types/node global typings #3582

Closed
kris7t opened this issue Nov 22, 2022 · 1 comment · Fixed by #3583 or #3601
Closed

mobx 6.7.0 leaks @types/node global typings #3582

kris7t opened this issue Nov 22, 2022 · 1 comment · Fixed by #3583 or #3601
Labels

Comments

@kris7t
Copy link

kris7t commented Nov 22, 2022

Intended outcome: When using mobx in a TypeScript in a frontend-only project, it should be possible to use the DOM typings for globals such as setTimeout (which should return a number).

Actual outcome: The globals get their typings from @types/node, because mobx/dist/api/when.d.ts contains a spurious

/// <reference types="node" />

since 223e368. Unfortunately, global typings referenced by imported files are automatically propagated to importing packages: microsoft/TypeScript#22331 (comment)

In particular, setTimeout now return NodeJS.Timeout even if "node" is omitted from compilerOptions.types in tsconfig.json. Globals not present in DOM, such as process, are also visible, which is particularly dangerous for type safety.

How to reproduce the issue:

Create a TypeScript project with a tsconfig.json containing

{
    "compilerOptions": {
        "libs": []
    }
}

Observe that if mobx 6.6.2 is imported in the project, globals like setTimeout have their types as specified in DOM (e.g., setTimeout returns number): https://codesandbox.io/s/currying-worker-yj8gt6?file=/index.tsx

If mobx 6.7.0 is imported, the globals have their types as in @types/node, because mobx references the node global typings: https://codesandbox.io/s/sleepy-bird-dh354u?file=/index.tsx

Versions

  • typescript 4.9.3
  • mobx 6.7.0
kris7t added a commit to graphs4value/refinery that referenced this issue Nov 22, 2022
Also bumps some dependencies and updates tsconfig.json

The added workarounds should be remove once
mobxjs/mobx#3582 is resolved.
@urugator
Copy link
Collaborator

Thank you for the report.
PR #3583.
Let me know if there is a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants