TypeScript Interfaces

The TypeScript Generator allows you to create TypeScript interfaces that you can embed in any TypeScript-enabled project (React, Vue.js, Angular..).

TypeScript ジェネレーターを使用すると、TypeScript 対応プロジェクト (React、Vue.js、Angular..) に埋め込むことができる TypeScript インターフェースを作成できます。

To do so, run the generator:

これを行うには、ジェネレーターを実行します。

npm init @api-platform/client https://demo.api-platform.com src/ -- --generator typescript --resource foo
# Replace the URL with the entrypoint of your Hydra-enabled API.

src/ is where the interfaces will be generated.

src/ は、インターフェイスが生成される場所です。

Omit the resource flag to generate files for all resource types exposed by the API. You can also use an OpenAPI documentation with -f openapi3.

API によって公開されるすべてのリソース タイプのファイルを生成するには、リソース フラグを省略します。また、-f openapi3 で OpenAPI ドキュメントを使用することもできます。

This command parses the Hydra documentation and creates one .ts file for each API Resource you have defined in your application, in the interfaces subfolder.

このコマンドは、Hydra ドキュメントを解析し、アプリケーションで定義した API リソースごとに 1 つの .ts ファイルを interfaces サブフォルダーに作成します。

Note: If you are not sure what the entrypoint is, see Troubleshooting.

注: エントリポイントが不明な場合は、トラブルシューティングを参照してください。

Example

Assuming you have 2 resources in your application, Foo and Bar, when you run:

実行時に、アプリケーションに Foo と Bar の 2 つのリソースがあると仮定します。

npm init @api-platform/client https://demo.api-platform.com src/ -- --generator typescript

You will obtain 2 .ts files arranged as following:

次のように配置された 2 つの .ts ファイルを取得します。

  • src/
    ソース/
  • interfaces/
    • foo.ts
      フット・ツ
    • bar.ts
      bar.ts