-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hous 61/add type script to the map #5
base: develop
Are you sure you want to change the base?
Conversation
Markers view will be fixed in when I link Map with our API to get location data.
let coord : Coord =[0,0] | ||
const addressesList = await response; | ||
|
||
addressesList.forEach((house:House, i:number) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i
doesn't need its type to be specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS shout when type is undefined.
|
||
addressesList.forEach((house:House, i:number) => { | ||
const address = `${house.city} ${house.streetNumber} ${house.streetName}`; | ||
geocoder.geocode({ address }, (results:[{geometry:{location:{lat:()=>number,lng:()=>number}}}], status:string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's WIP but the type of this complexity: [{geometry:{location:{lat:()=>number,lng:()=>number}}}]
would be best declared outside of this function, like you did with House
as it makes it easier to read.
src/components/Map/GoogleMapComp.tsx
Outdated
|
||
export default function GoogleMapComp({ houses, style }:{houses:House,style:CSS.Properties}) { | ||
function Map() { | ||
let [housesCoords, setHousesCoords]:[Coord[],Dispatch<SetStateAction<Coord[]>>] = useState<Coord[]>([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to declare the types of [state, setState]
right after declaring them as TS will know their types thanks to the way it works with React, so
let [housesCoords, setHousesCoords] = useState<Coord[]>([]);
will do and using const
instead let
would be advisable. Sometimes you don't have to declare the type even inside the <> after useState
but it's generally a good practise to do so even when the type of a state can be guessed from an initial value of a state.
src/components/Map/GoogleMapComp.tsx
Outdated
|
||
export default function GoogleMapComp({ houses, style }:{houses:House,style:CSS.Properties}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be a good idea to declare an interface or type with {houses:House,style:CSS.Properties}
above the function to make it easier to read.
No description provided.