将 TypeScript 与 IMA SDK 搭配使用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
TypeScript 是一种强类型的面向对象编程语言,可编译为 JavaScript。TypeScript 是 JavaScript 的超集,支持 JavaScript 的所有功能,以及可选的静态类型。TypeScript 工具有助于检测和防范您在纯 JavaScript 中可能不会注意到的 bug。
开始使用
DefinitelyTyped 是一个开源项目,用于维护许多软件包(包括 IMA SDK 库)的类型声明文件的代码库。您可以使用 npm 从 @types/google_interactive_media_ads_types 软件包安装 IMA 类型。
npm install --save-dev @types/google_interactive_media_ads_types
安装完成后,您可以在自己的代码中访问 google.ima
对象公开的所有类型。您还可以在具有这些功能的源代码编辑器(例如 Visual Studio Code)中,针对 IMA 方法和属性使用代码补全和内容协助功能。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-10。
[null,null,["最后更新时间 (UTC):2025-08-10。"],[[["\u003cp\u003eTypeScript is a strongly typed, object-oriented programming language that compiles to JavaScript and supports all of JavaScript's features plus optional static typing.\u003c/p\u003e\n"],["\u003cp\u003eTypeScript tooling helps in detecting and preventing bugs that might go unnoticed in plain JavaScript.\u003c/p\u003e\n"],["\u003cp\u003eDefinitelyTyped is an open-source project containing type declaration files for various packages, including the IMA SDK library.\u003c/p\u003e\n"],["\u003cp\u003eInstalling the IMA types using npm from the @types/google-interactive-media-ads package gives you access to all types exposed by the google.ima object.\u003c/p\u003e\n"],["\u003cp\u003eAfter installation, source code editors with features like code completion and content assist can be used to take full advantage of IMA methods and properties.\u003c/p\u003e\n"]]],[],null,["# Use TypeScript with the IMA SDK\n\n[TypeScript](//www.typescriptlang.org/) is a strongly typed, object-oriented\nprogramming language that compiles to JavaScript. TypeScript is a superset of\nJavaScript, and supports all of JavaScript's features plus optional\n[static typing](//en.wikipedia.org/wiki/Type_system#STATIC).\n[TypeScript tooling](http://www.typescriptlang.org/docs/handbook/2/basic-types.html#types-for-tooling)\ncan help detect and prevent bugs that you might not notice in plain JavaScript.\n\nGet started\n-----------\n\n[DefinitelyTyped](//github.com/DefinitelyTyped/DefinitelyTyped) is an open\nsource project that maintains a repository of type\n[declaration files](//www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)\nfor many packages, including the IMA SDK library. You can install the IMA types\nwith [npm](//docs.npmjs.com/about-npm) from the\n[@types/google_interactive_media_ads_types](//www.npmjs.com/package/@types/google_interactive_media_ads_types)\npackage. \n\n npm install --save-dev @types/google_interactive_media_ads_types\n\nAfter installation, you have access to all of the types exposed by the\n[`google.ima`](/interactive-media-ads/docs/sdks/html5/client-side/reference/ts)\nobject in your own code. You can also take advantage of code completion and\ncontent assist for IMA methods and properties in source code editors that have\nthose features, for example, [Visual Studio Code](https://code.visualstudio.com/docs/languages/typescript)."]]