あいつの日誌β

働きながら旅しています。

TypeScript

error TS7018: Object literal's property 'xxx' implicitly has an 'any' type.

こんな感じのオブジェクトに const obj = { hoge: "", fuga: "", piyo: "" }; null なプロパティを追加すると怒られる const obj = { hoge: "", fuga: "", piyo: "", xxx: null }; any 型の object だとプロパティに any を許容するけどこの場合は型推論が働…

TypeScript で Promise を使った例

compileOptions で target を es6 にしておけば import {Promise} from 'es6-promise' は不要らしい 準備 % mkdir practice-ts-pattern && cd $_ % npm init --yes create tsling.json: % tslint --init % cat << EOF > tsconfig.json { "version": "1.7.5",…

TypeScript で callback しようとしたらエラーになって悩んだ

どうした? とりあえず環境を用意します % mkdir practice-ts-callback && cd $_ % tslint init % npm init --yes % npm install co --save % dtsm init % dtsm install node --save ひとまず compilerOptions は以下のようにします。 create tsconfig.json:…

TypeScript で co + generators したい

どうした? callback 地獄は嫌いです。 それで? とりあえず環境を用意します % mkdir practice-ts-generatpr && cd $_ % tslint init % npm init --yes % npm install co --save % dtsm init % dtsm install node --save create generator.ts: /// <reference path="./typings/bundle.d.ts" /> const c</reference>…

TypeScript と Node.js で hello, world をする http server を作る

Story: あらすじ ひょんな事から TypeScript で Node.js のサーバーサイドエンジニアやる事になりました。 Enviroments: 環境 % sw_vers ProductName: Mac OS X ProductVersion: 10.11.3 BuildVersion: 15D21 % node -v v4.2.6 % npm -v 2.14.12 % tsc -v me…