Azure Functions + TypeScript 公式に型定義が追加されたらしい

Azure Functions + TypeScript 公式に型定義が追加されたらしい:


Azure Functions の型定義



Screen Shot 2019-01-15 at 17.08.58.png


2019/01/15の段階で、出来立てホヤホヤです。

このパッケージには、Azure Functions でTypeScriptを使用するための型定義が含まれています。

これらのタイピングは、Azure Functions Functions コードに渡される一般的なオブジェクト用です。 Azure FunctionsはTypeScriptの開発をサポートしていますが、TranspilationなしでTypeScriptコードを直接実行することはサポートしていません。
とのことです。とりあえず手動でトランスパイルして試します。

bash
mkdir func 
cd func 
func init 
# 1. dotnet 
# 2. node 
# 3. python 
Choose option: 2 
# node 
# Writing .gitignore 
# Writing host.json 
# Writing local.settings.json 
# Writing /Users/hoge/func/.vscode/extensions.json 
 
func new  
#Select a template:  
# 5. HTTP trigger 
# 6. Azure Queue Storage trigger 
# Choose option: 5 
# HTTP trigger 
# Function name: [HttpTrigger] returnName 
# Writing /Users/hoge/func/returnName/index.js 
# Writing /Users/hoge/func/returnName/sample.dat 
# Writing /Users/hoge/func/returnName/function.json 
# The function "returnName" was created successfully from the "HTTP trigger" template. 
 
tsc --init 
npm init 
npm i --save-dev @azure/functions 
returnName/index.ts
import { AzureFunction, Context, HttpRequest } from "@azure/functions"; 
 
const index: AzureFunction = async function (context: Context, req: HttpRequest) { 
    context.log('JavaScript HTTP trigger function processed a request.'); 
    if (req.query.name || (req.body && req.body.name)) { 
        context.res = { 
            status: "200", 
            body: "Hello " + (req.query.name || req.body.name) 
        }; 
    } else { 
        context.res = { 
            status: 400, 
            body: "Please pass a name on the query string or in the request body" 
        }; 
    } 
} 
 
export { index }; 
とりあえず最低限だけ

tsconfig.json
{ 
  "compilerOptions": { 
    "target": "es2015", 
    "module": "commonjs", 
    "lib": ["es2015"], 
    "sourceMap": true, 
    "strict": true 
  }, 
  "include": [  
    "**/*.ts"  
  ], 
  "exclude": [ 
    "node_modules", 
    "**/*.spec.ts" 
  ] 
} 
 
bash
tsc 
func start 
実行!
 
                  %%%%%% 
                 %%%%%% 
            @   %%%%%%    @ 
          @@   %%%%%%      @@ 
       @@@    %%%%%%%%%%%    @@@ 
     @@      %%%%%%%%%%        @@ 
       @@         %%%%       @@ 
         @@      %%%       @@ 
           @@    %%      @@ 
                %% 
                % 
 
Azure Functions Core Tools (2.1.748 Commit hash: 5db20665cf0c11bedaffc96d81c9baef7456acb3) 
Function Runtime Version: 2.0.12134.0 
[01/15/2019 08:05:12] Building host: startup suppressed:False, configuration suppressed: False 
[01/15/2019 08:05:12] { 
[01/15/2019 08:05:12]   "version": "2.0" 
[01/15/2019 08:05:12] } 
[01/15/2019 08:05:13] Initializing Host. 
... 
略 
... 
Hosting environment: Production 
Content root path: /Users/hoge/func 
Now listening on: http://0.0.0.0:7071 
Application started. Press Ctrl+C to shut down. 
Listening on http://0.0.0.0:7071/ 
Hit CTRL-C to exit... 
 
Http Functions: 
 
    returnName: [GET,POST] http://localhost:7071/api/returnName 
 
TypeScriptいいね。

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)