---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/typescript.md
  - https://yandex.com/dev/games/doc/hi/sdk/typescript.md
  - https://yandex.com/dev/games/doc/ko/sdk/typescript.md
  - https://yandex.com/dev/games/doc/ru/sdk/typescript.md
  - https://yandex.com/dev/games/doc/tr/sdk/typescript.md
  - https://yandex.com/dev/games/doc/vi/sdk/typescript.md
  - https://yandex.com/dev/games/doc/zh/sdk/typescript.md
  - href: zh/sdk/typescript.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/zh/llms.txt

# TypeScript

<!-- source: zh/_includes/script-common.md -->
<!-- source: zh/_includes/script/index-js.md -->

<!-- endsource: zh/_includes/script/index-js.md -->

<!-- source: zh/_includes/script/requirements-js.md -->

<!-- endsource: zh/_includes/script/requirements-js.md -->

<!-- source: zh/_includes/script/image-modal-js.md -->

<!-- endsource: zh/_includes/script/image-modal-js.md -->
<!-- endsource: zh/_includes/script-common.md -->

要将 SDK 添加到使用 TypeScript 开发的游戏中：

1. 按照 [Node.JS](https://nodejs.org/en/){.external} 网站上的说明安装 `npm`。
2. 为 SDK 添加类型支持，安装包 [@types/ysdk](https://www.npmjs.com/package/@types/ysdk){.external}：

    ```console
    npm install --save @types/ysdk
    ```

3. 在项目文件中导入所需的 SDK 模块类型。例如，可以这样导入类型 `ysdk` 和 `player`：

    ```typescript showLineNumbers
    // 导入必要的 SDK 模块类型。
    import type { SDK, Player } from 'ysdk';

    ...

    // 使用类型的 SDK 示例。
    const ysdk: SDK = await YaGames.init();
    const player: Player = await ysdk.getPlayer();
    ```

---


<a href="https://www.npmjs.com/package/@types/ysdk">
  <span class="button">存储库</span>
</a>
