google-place-fields
TypeScript definitions for Google Places API v1 fields, providing strongly-typed interfaces for responses from the Google Places API.
Installation
npm install google-place-fields
pnpm install google-place-fields
yarn add google-place-fields
Usage
This package provides TypeScript interfaces for Google Places API v1 responses. You can use these interfaces to type-check your Google Places API responses.
import {
Place,
PlaceDetailsResponse,
SearchPlacesResponse,
GooglePlaceConverter
} from 'google-place-fields';
async function getPlaceDetails(placeName: string): Promise<Place> {
const response = await fetch(`https://places.googleapis.com/v1/${placeName}?key=YOUR_API_KEY`);
const data = await response.json();
const typedResponse = GooglePlaceConverter.toPlaceDetailsResponse(data);
return typedResponse.place;
}
async function searchPlaces(query: string): Promise<Place[]> {
const response = await fetch(`https://places.googleapis.com/v1/places:searchText`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Goog-Api-Key': 'YOUR_API_KEY'
},
body: JSON.stringify({ textQuery: query })
});
const data = await response.json();
const typedResponse = GooglePlaceConverter.toSearchPlacesResponse(data);
return typedResponse.places;
}
Available Types
This package includes comprehensive type definitions for Google Places API v1 responses, including:
Place
: The main interface representing a place with all its propertiesLocalizedText
: Interface for localized text content with language codeAddressComponent
: Interface for structured address componentsPlusCode
: Interface for Plus Code location referenceLatLng
: Interface for geographical coordinatesViewport
: Interface for location viewportAuthorAttribution
: Interface for author informationReview
: Interface for place reviewsPhoto
: Interface for place photosOpeningHours
: Interface for opening hours dataPeriod
: Interface for time periods when a place is openPoint
: Interface for opening/closing time pointsTimePeriod
: Interface for time periodsBusinessStatus
: Enum for business operation statusPriceRange
: Interface for price level informationMoney
: Interface for representing currency amountsFuelOptions
: Interface for fuel station informationEVChargeOptions
: Interface for EV charging station dataAccessibilityOptions
: Interface for accessibility informationGoogleMapsLinks
: Interface for various Google Maps action links
All types are fully documented with JSDoc comments directly from the Google Places API documentation.
Documentation
All interfaces are based on the Google Places API v1 Reference.
Features
- Full TypeScript type definitions for Google Places API v1
- Detailed JSDoc comments on all interfaces and properties
- Utility converter class to easily transform API responses into typed objects
- Support for all field types in the Places API including specialized fields like EV charging, fuel options, etc.
- Enums for all enumerable values from the API
License
MIT