npm i typescript code example

Example 1: install typescript

npm install -g typescript

Example 2: npm typescript

npm install -g typescript

Example 3: npm typescript package

{
   "compilerOptions": {
       "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
       "module": "commonjs",
       "allowJs": true, /* Allow javascript files to be compiled. */
       "strict": true, /* Enable all strict type-checking options. */
       "outDir": "./lib", /* Redirect output structure to the directory. */
       "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
   },
   "include": ["src"],
   "exclude": ["node_modules"]
}

Example 4: npx run ts file

npx ts-node src/foo.ts

Example 5: npm typescript package

const demoMethod = () => {
returnI’m Duffer”;
}
module.exports = demoMethod;