Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9095

typescript environment

$
0
0
npm i -g typescript

then you can use tsc command to compile ts files to js files.

D:\workspace\type-test>tsc app.ts -w
[19:47:56] Starting compilation in watch mode...
tsc --init
message TS6071: Successfully created a tsconfig.json file.
tsconfig.json
{"compilerOptions":{"target":"es5",/*SpecifyECMAScripttargetversion:'ES3'(default),'ES5','ES2015','ES2016','ES2017','ES2018','ES2019','ES2020',or'ESNEXT'.*/"module":"commonjs",/*Specifymodulecodegeneration:'none','commonjs','amd','system','umd','es2015','es2020',or'ESNext'.*/"outDir":"./dist",/*Redirectoutputstructuretothedirectory.*/"rootDir":"./src",/*Specifytherootdirectoryofinputfiles.Usetocontroltheoutputdirectorystructurewith--outDir.*//*StrictType-CheckingOptions*/"strict":true,/*Enableallstricttype-checkingoptions.*/"moduleResolution":"node",/*Specifymoduleresolutionstrategy:'node'(Node.js)or'classic'(TypeScriptpre-1.6).*/"esModuleInterop":true,/*EnablesemitinteroperabilitybetweenCommonJSandESModulesviacreationofnamespaceobjectsforallimports.Implies'allowSyntheticDefaultImports'.*//*AdvancedOptions*/"forceConsistentCasingInFileNames":true/*Disallowinconsistently-casedreferencestothesamefile.*/}}
npm init -y
Wrote to D:\workspace\type-test\package.json:

{
  "name": "type-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
npm i -D typescript ts-node nodemon @types/node

then use nodes api like

import * as http from 'http';
nodemon.json
{"watch":["src"],"ext":".ts,.js","ignore":[],"exec":"ts-node ./src/app.ts"}
npx nodemon

when changes happened in src fold, ts-node ./src/app.ts will be executed.

ESlint

install vscode extension ESlint

npm install -g -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin 

Inside VS Code use: Ctrl+Shift+P or Shift+Cmd+P
Preferences: Open Settings (JSON)

setting.json
{"eslint.validate":["typescript"]}

create .eslintrc.json

eslintrc.json
{"parser":"@typescript-eslint/parser","plugins":["@typescript-eslint"],"rules":{"semi":["error","never"],"quotes":[2,"single"]},"parserOptions":{"ecmaVersion":6,"sourceType":"module","ecmaFeatures":{"modules":true}}}
eslint

that's all. cool!


Viewing all articles
Browse latest Browse all 9095

Latest Images

Trending Articles