microsoft/TypeScript

Should we set '"types": []' for 'tsc init'?

DanielRosenwasser opened this issue ยท 6 comments

Very few people understand the automatic @types inclusion behavior, it often causes packages to conflict, and it is often a program construction performance foot-gun.

Maybe we should output a field like this in compilerOptions.

// Add packages with global definitions that can't be imported here.
// Remove entirely to auto-include all '@types' packages.
"types": []

What do others here think?

orta commented

Yes

Hmm, also yes

+1 from me. It was my first step in several TS projects to define "types" fields in every tsconfig.json with explicit type imports to prevent pollution of the code with unneded types from node_modules (e.g., I want @types/node in the grunt scripts, but not in the web scripts, and so on).

Bnaya commented

I'm also +1, as setting specific "types" :[] entry (and lib) is the first thing after tsc --init for me
But it might hinder the autocomplete/auto import features of yet-to-be imported packages, so it must be very documented

From discussion in the design meeting: we would like to do this, but only after we've come up with a basic @types/node workflow that's as easy as the current one:

  1. import * as fs from "fs"
  2. error "you need to install @types/node."
  3. $ npm i @types/node
  4. Done.

Same for jest, when using describe or expect.

Bnaya commented

Maybe add new error + autofix for this kind of things?