Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
TypeScript — это типизированное надмножество JavaScript, которое компилируется в обычный JavaScript. Фрагмент ниже демонстрирует простое использование Google Карт с помощью TypeScript.
Типы обычно не содержат свойств, функций или классов, присутствующих в альфа- или бета-версиях. Во многих случаях объект можно привести к правильному типу.
Следующая ошибка вызвана свойством mapId beta для MapOptions .
error TS2345: Argument of type '{ center: google.maps.LatLng; zoom: number;
mapId: string; }' is not assignable to parameter of type 'MapOptions'. Object
literal may only specify known properties, and 'mapId' does not exist in type
'MapOptions'.
Указанную выше ошибку можно исправить с помощью приведенного ниже состава.
Некоторые библиотеки могут использовать пакет, отличный от @types/google.maps , что может приводить к конфликтам. Используйте опцию компилятора skipLibCheck , чтобы избежать проблем с несоответствием типов.
{"compilerOptions":{"skipLibCheck":true}}
Укажите типRoots
Некоторые фреймворки, такие как Angular, могут потребовать указания параметра компилятора typeRoots для включения типов, установленных из @types/google.maps и всех других пакетов «@types».
[[["Прост для понимания","easyToUnderstand","thumb-up"],["Помог мне решить мою проблему","solvedMyProblem","thumb-up"],["Другое","otherUp","thumb-up"]],[["Отсутствует нужная мне информация","missingTheInformationINeed","thumb-down"],["Слишком сложен/слишком много шагов","tooComplicatedTooManySteps","thumb-down"],["Устарел","outOfDate","thumb-down"],["Проблема с переводом текста","translationIssue","thumb-down"],["Проблемы образцов/кода","samplesCodeIssue","thumb-down"],["Другое","otherDown","thumb-down"]],["Последнее обновление: 2025-08-27 UTC."],[[["\u003cp\u003eTypeScript can enhance Google Maps development by providing static typing and improved code maintainability.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003e@types/google.maps\u003c/code\u003e package from DefinitelyTyped for TypeScript support in your Google Maps projects.\u003c/p\u003e\n"],["\u003cp\u003eAlpha and beta Google Maps features may require type casting to avoid TypeScript errors.\u003c/p\u003e\n"],["\u003cp\u003eIn case of conflicting type definitions, consider utilizing the \u003ccode\u003eskipLibCheck\u003c/code\u003e compiler option to bypass type checking of external libraries.\u003c/p\u003e\n"],["\u003cp\u003eWhen necessary, configure \u003ccode\u003etypeRoots\u003c/code\u003e in your TypeScript configuration to ensure proper inclusion of Google Maps type definitions.\u003c/p\u003e\n"]]],[],null,["# TypeScript and Google Maps\n\n[TypeScript](https://www.typescriptlang.org/) is a typed superset of JavaScript\nthat compiles to plain JavaScript. The snippet below demonstrates simple usage\nof Google Maps using TypeScript. \n\n let map: google.maps.Map;\n const center: google.maps.LatLngLiteral = {lat: 30, lng: -110};\n\n function initMap(): void {\n map = new google.maps.Map(document.getElementById(\"map\") as HTMLElement, {\n center,\n zoom: 8\n });\n }\n\nGetting Started\n---------------\n\nThe\n[DefinitelyTyped project](https://github.com/DefinitelyTyped/DefinitelyTyped) is\nan open source projects that maintains type\n[declaration files](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)\nfor many packages including Google Maps. The Google Maps JavaScript declaration\nfiles (see\n[source files](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google.maps)\non GitHub) can be installed using NPM from the\n[@types/google.maps](https://www.npmjs.com/package/@types/google.maps) package. \n\n npm i -D @types/google.maps\n\n| **Note:** These types are automatically generated. To report an issue with these types, open a [support ticket](https://issuetracker.google.com/issues/new?component=188853&template=788207).\n\nAlpha and Beta Features\n-----------------------\n\nThe\n[types](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google.maps)\ntypically don't have the properties, functions, or classes found in alpha or\nbeta releases. In many of these cases, the object can be cast to the correct\ntype.\n\nThe following error is caused by the `mapId` beta property for `MapOptions`. \n\n```\nerror TS2345: Argument of type '{ center: google.maps.LatLng; zoom: number;\nmapId: string; }' is not assignable to parameter of type 'MapOptions'. Object\nliteral may only specify known properties, and 'mapId' does not exist in type\n'MapOptions'.\n```\n\nThe above error can be corrected with the cast below. \n\n { center: {lat: 30, lng: -110}, zoom: 8, mapId: '1234' } as google.maps.MapOptions\n\nConflicting @types packages\n---------------------------\n\nSome libraries may use a package other than\n[@types/google.maps](https://www.npmjs.com/package/@types/google.maps),\nwhich may cause conflicts. Use the\n[skipLibCheck](https://www.typescriptlang.org/tsconfig#skipLibCheck)\ncompiler option to avoid issues with inconsistent types. \n\n {\n \"compilerOptions\": {\n \"skipLibCheck\": true\n }\n }\n\nSpecify typeRoots\n-----------------\n\nSome frameworks such as Angular may require specifying the\n[typeRoots](https://www.typescriptlang.org/tsconfig#typeRoots)\ncompiler option to include types installed from\n[@types/google.maps](https://www.npmjs.com/package/@types/google.maps)\nand all other \"@types\" packages.\n**Note:** By default all visible \"@types\" packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible. \n\n {\n ...\n \"compilerOptions\": {\n ...\n \"typeRoots\": [\n \"node_modules/@types\",\n ],\n ...\n }\n }"]]