Stay organized with collections
Save and categorize content based on your preferences.
TypeScript is a typed superset of JavaScript
that compiles to plain JavaScript. The snippet below demonstrates simple usage
of Google Maps using TypeScript.
The
types
typically don't have the properties, functions, or classes found in alpha or
beta releases. In many of these cases, the object can be cast to the correct
type.
The following error is caused by the mapId beta property for 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'.
The above error can be corrected with the cast below.
Some libraries may use a package other than
@types/google.maps,
which may cause conflicts. Use the
skipLibCheck
compiler option to avoid issues with inconsistent types.
{"compilerOptions":{"skipLibCheck":true}}
Specify typeRoots
Some frameworks such as Angular may require specifying the
typeRoots
compiler option to include types installed from
@types/google.maps
and all other "@types" packages.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-18 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](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\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, please open a [support ticket](https://issuetracker.google.com/savedsearches/558438).\n\nAlpha and Beta Features\n\nThe\n[types](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google.maps)\ntypically do not 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\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\nSpecifying typeRoots\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 }"]]