Typescript development environment

I am starting with typescript. I started with an empty folder and ran these commands to set up my typescript development.

  npm init 
  npm install typescript
  npm install @types/node  

then i made a tsconfig file

npx tsc --init

I tried changing my output dir in tsconfig.json like "outDir": "./dist",

But that doesn’t seem to work. the transpiled file is still coming into the src folder. I have a folder structure like :

                   root
                   |_ node_modules
                   |_ src
                     |_ index.ts
                   |_ dist
                   |_package.json
                   |_tsconfig.json
                   |_package-lock.json

Here is the tsconfig.json file

"compilerOptions": {
               "target": "es5",                          
               "module": "commonjs",
               "outDir": "./dist",                        
               "rootDir": "./src",    
               "strict": true,
               "esModuleInterop": true, 
               "skipLibCheck": true,                         
               "forceConsistentCasingInFileNames": true
  }
}

Answer

Just use tsc. You just specify one file. TypeScript doesn’t worry about making it work as a module by itself as you don’t have a need for modules with just one file. Oh also, from the cli reference:

Transpile just the index.ts with the compiler defaults tsc index.ts