microsoft/TypeScript

Consult `package.json` contents when creating `tsconfig.json` under `tsc --init` to determine better defaults

DetachHead opened this issue ยท 2 comments

Bug Report

๐Ÿ”Ž Search Terms

tsc init module commonjs

๐Ÿ•— Version & Regression Information

4.9.0-dev.20221017

โฏ Playground Link

n/a

๐Ÿ’ป Code

package.json

{
  "name": "asdf",
  "version": "1.0.0",
  "description": "",
  "author": "",
  "license": "ISC",
  "type": "module",
  "devDependencies": {
    "typescript": "^4.9.0-dev.20221017"
  }
}

๐Ÿ™ Actual behavior

> npx tsc --init

Created a new tsconfig.json with:                                                                                       
                                                                                                                     TS 
  target: es2016
  module: commonjs
  strict: true
  esModuleInterop: true
  skipLibCheck: true
  forceConsistentCasingInFileNames: true


You can learn more at https://aka.ms/tsconfig

๐Ÿ™‚ Expected behavior

it should check the package.json to determine that module should be nodenext or something

moduleResolution should also default to nodenext or node16 when "type": "module" is in package.json.

also, maybe it would be better to not even include these options when running tsc --init and instead just infer the default values from package.json when they are not present in tsconfig.json