You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
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 anumber
).Actual outcome: The globals get their typings from
@types/node
, becausemobx/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 returnNodeJS.Timeout
even if"node"
is omitted fromcompilerOptions.types
intsconfig.json
. Globals not present in DOM, such asprocess
, are also visible, which is particularly dangerous for type safety.How to reproduce the issue:
Create a TypeScript project with a
tsconfig.json
containingObserve that if mobx 6.6.2 is imported in the project, globals like
setTimeout
have their types as specified in DOM (e.g.,setTimeout
returnsnumber
): https://codesandbox.io/s/currying-worker-yj8gt6?file=/index.tsxIf 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.tsxVersions
The text was updated successfully, but these errors were encountered: