TypeScript はじめました
表題のとおり、TypeScript を使うことにしました。
ということで特に他に書くことないので、備忘録だけ置いておくことにします。当方の JavaScript のソース状況としては Cloud Functions for Firebase での functions/index.js
のみでした。
cd functions
yarn add -D typescript tslint
package.json
"scripts": {
"tslint": "tslint --project tsconfig.json",
"tsc": "tsc",
...
tsconfig.json
{
"compilerOptions": {
"lib": ["es6"],
"module": "commonjs",
"noImplicitReturns": true,
"outDir": "./",
"sourceMap": true,
"target": "es6"
},
"compileOnSave": true,
"include": ["src"],
"exclude": ["node_modeles"]
}
cp -f index.js src/index.ts
既存のソース functions/index.js
を丸ごと functions/src/index.ts
にコピー&ペースト
yarn tsc
error Property '~~~' does not exist on type '{}'.
error Property '~~~' does not exist on type '{}'.
error Property '~~~' does not exist on type '{}'.
error Property '~~~' does not exist on type '{}'.
error Property '~~~' does not exist on type '{}'.
...
以上エラー処理して完了。
やったぜ。