Open3
TypeScript NodeJS Memo
moment js を利用する場合
下記のサイトを参考
import moment from 'moment';
function hello(name: string): string {
return `Hello, ${name}!`+(moment()).format();
}
console.log(hello("World"));
入門編
下記を参考に開始した。
重要なところを抽出
npm init -y
npm install -D typescript @types/node@12
npx tsc --init
nano tsconfig.json
nano src/index.ts
npx tsc
node dist/index.js
単一ファイルにコンパイル
下記の方法でできるものと思われる。
しかし、下記のエラーが発生。コンパイラなどの環境が異なるためと思われる。
tsconfig.json:8:5 - error TS6082: Only 'amd' and 'system' modules are supported alongside --outFile.
8 "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
~~~~~~~~
tsconfig.json:16:5 - error TS6082: Only 'amd' and 'system' modules are supported alongside --outFile.
16 "outFile": "./dist/index.js", /* Concatenate and emit output to single file. */
~~~~~~~~~
Found 2 errors.