Upgrade to Pro — share decks privately, control downloads, hide ads and more …

tsconfig.jsonを完全に理解する

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for pco2699 pco2699
October 08, 2019

 tsconfig.jsonを完全に理解する

Avatar for pco2699

pco2699

October 08, 2019
Tweet

More Decks by pco2699

Other Decks in Programming

Transcript

  1. example - tsconfig.json example - tsconfig.json { "compilerOptions": { "noImplicitAny":

    true, "removeComments": true, "preserveConstEnums": true, "outFile": "../../built/local/tsc.js", }, "include": [ "src/**/*" ], "exclude": [ "node_modules", "**/*.spec.ts" ] } 7 
  2. project structure project structure ./home ├── tsconfig-base.json ├── src │

    └── tsconfig.json └── test # srcの型やソースコードに依存している └── tsconfig.json 10 . 3 
  3. $ tsc --init { "compilerOptions": { "target": "es5", // コンパイル後のJSのバージョン

    "module": "commonjs", // コンパイル後のimport/export方式 "strict": true, "esModuleInterop": true } } 13 
  4. strictで怒られる簡単なコード strictで怒られる簡単なコード const hoge = (input) => { // noImplicitAny

    error console.log(input); } hoge(1); const piyo: number = null; // strictNullChecks error 14 . 2 
  5. その他 その他 alwaysStrict: JSの use strictモードを有効化 strictBindCallApply: call,apply,bindも型チェック noImplicitThis: 暗黙のthis引き渡しを禁⽌

    strictFunctionTypes: 関数引数の双変性を無効 strictPropertyInitialization: プロパティ初期化必須 14 . 3 
  6. CommonJs import/export CommonJs import/export // export const hoge = ()

    => { // ...some func } exports = hoge // import const moment = require("hoge"); moment(); 15 . 3 
  7. ES6 Module import/export ES6 Module import/export // export export const

    hoge = () => { // ...some func }; // import import { hoge } from 'hoge'; hoge(); 15 . 4 
  8. export: CommonJs import: ES6 Module export: CommonJs import: ES6 Module

    esmoduleInterop: false esmoduleInterop: false esmoduleInterop: true esmoduleInterop: true import * as hoge from './hoge' hoge(); // *を呼び出すのはES6 Moduleの規約NG // CommonJSをdefault importでimportできる import hoge from './hoge' hoge(); // ES6 Module準拠 15 . 5 