Anber / wyw-in-js

MIT License
191 stars 8 forks source link

`@wyw-in-js/shared` produces `/// <reference types="node" />` which means anything including it enables global node types #33

Closed antitoxic closed 4 months ago

antitoxic commented 6 months ago

Environment

Description

  1. @wyw-in-js/shared produces /// <reference types="node" /> in @wyw-in-js/shared/types/options/types.d.ts
  2. In its own turn @wyw-in-js/shared/types/options/types.d.ts gets imported by @wyw-in-js/shared/types/options/isFeatureEnabled.d.ts and then this by @wyw-in-js/shared/types/index.d.ts
  3. This makes anything importing @wyw-in-js/shared automatically include all node.js specific type definitions even if it's a browser-facing project.
  4. @linaria/core includes @wyw-in-js/shared so you can understand that this is a problem since @linaria/core is imported by all web-facing projects

Reproducible Demo

  1. Install @linaria/core in project where nodejs modules are NOT included.
  2. Import @linaria/core in a ts file.
  3. Create a timer like const timerId: number = setTimeout(...)
  4. tsc will fail with: TS2322: Type Timeout is not assignable to type number because nodejs types flooded the global scope.
  5. If you don't include @linaria/core you don't get the error.