Azure Functions + TypeScript 公式に型定義が追加されたらしい
Azure Functions + TypeScript 公式に型定義が追加されたらしい:
2019/01/15の段階で、出来立てホヤホヤです。
とりあえず最低限だけ
TypeScriptいいね。
Azure Functions の型定義
2019/01/15の段階で、出来立てホヤホヤです。
- npmjs はこちら
https://www.npmjs.com/package/@azure/functions - github はこちら
https://github.com/Azure/azure-functions-nodejs-worker/tree/dev/types/public
このパッケージには、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
コメント
コメントを投稿