Skip to content

Hous 61/add type script to the map#5

Open
shadowas-py wants to merge 4 commits intodevelopfrom
HOUS-61/Add-TypeScript-to-the-map
Open

Hous 61/add type script to the map#5
shadowas-py wants to merge 4 commits intodevelopfrom
HOUS-61/Add-TypeScript-to-the-map

Conversation

@shadowas-py
Copy link

No description provided.

Wojciech Okularczyk added 3 commits April 4, 2022 01:47
let coord : Coord =[0,0]
const addressesList = await response;

addressesList.forEach((house:House, i:number) => {
Copy link
Contributor

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.

Copy link
Author

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) => {
Copy link
Contributor

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.


export default function GoogleMapComp({ houses, style }:{houses:House,style:CSS.Properties}) {
function Map() {
let [housesCoords, setHousesCoords]:[Coord[],Dispatch<SetStateAction<Coord[]>>] = useState<Coord[]>([]);
Copy link
Contributor

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.

function Map() {
const [housesCoords, setHousesCoords] = useState([]);

export default function GoogleMapComp({ houses, style }:{houses:House,style:CSS.Properties}) {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants