-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
use-places-autocomplete.d.ts
84 lines (62 loc) 路 1.91 KB
/
use-places-autocomplete.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
declare module "use-places-autocomplete" {
// Hook
export type RequestOptions = Omit<
google.maps.places.AutocompletionRequest,
"input"
>;
export interface HookArgs {
requestOptions?: RequestOptions;
debounce?: number;
cache?: number | false;
cacheKey?: string;
googleMaps?: any;
callbackName?: string;
defaultValue?: string;
initOnMount?: boolean;
}
export type Suggestion = google.maps.places.AutocompletePrediction;
export type Status = `${google.maps.places.PlacesServiceStatus}` | "";
export interface Suggestions {
readonly loading: boolean;
readonly status: Status;
data: Suggestion[];
}
export interface SetValue {
(val: string, shouldFetchData?: boolean): void;
}
export interface ClearSuggestions {
(): void;
}
export interface ClearCache {
(key?: string): void;
}
export interface Init {
(): void;
}
export interface HookReturn {
ready: boolean;
value: string;
suggestions: Suggestions;
setValue: SetValue;
clearSuggestions: ClearSuggestions;
clearCache: ClearCache;
init: Init;
}
const usePlacesAutocomplete: (args?: HookArgs) => HookReturn;
export default usePlacesAutocomplete;
// Utils
export type GeoArgs = google.maps.GeocoderRequest;
export type GeocodeResult = google.maps.GeocoderResult;
export type GeoReturn = Promise<GeocodeResult[]>;
export const getGeocode: (args: GeoArgs) => GeoReturn;
export type LatLng = { lat: number; lng: number };
export const getLatLng: (result: GeocodeResult) => LatLng;
export type ZipCode = string | undefined;
export const getZipCode: (
result: GeocodeResult,
useShortName: boolean
) => ZipCode;
export type GetDetailsArgs = google.maps.places.PlaceDetailsRequest;
export type DetailsResult = Promise<google.maps.places.PlaceResult | string>;
export const getDetails: (args: GetDetailsArgs) => DetailsResult;
}