LoginSignup
0
0

More than 5 years have passed since last update.

Alexa Skill を TypeScriptで実装する

Posted at

まえがき

AlexaのJS実装をTSに置き換えてみます。

前提

Alexa Skillを作成した事がある方。
TSで記述したいと思った方。

インストール方法

インストール

$ npm install -g typescript

インストール確認

$ tsc --version
Version 3.3.4000

プロジェクトの作成

プロジェクト

以前の記事の【Alexa ASK CLI コマンドで東京リージョンにデプロイする】のプロジェクトをものに対応したいと思います。

TypeScriptの設定

Nodeの型情報をインストールする

$ npm install @types/node

設定

$ tsc --init

設定変更

$ cat tsconfig.json
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "sourceMap": true,
    "strict": true,  
    "esModuleInterop": true,
  },
  "files": [
    "index.ts"
  ]
}

※一部表示を省略しています。

TSファイルに変更

$ mv index.js index.ts

index.tsの修正

エラー内容を見つつ修正してください。

  • 基本的には以下の対応となると思います
    • import分の変更
    • 型情報の追加
    • 適切な型にキャスト

トランスパイル

$ tsc

まとめ

TS化が完了しました。あとはdeployコマンドでデプロイを行えば完了です。
型情報があるってやっぱりいいですね。
今回使用したソースはこちらにあります。

参考

初めてのスキル開発

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0