Hey Techies,
I was watching some random coding react conf video(If your a react developer you should try once). Guess what I found a hack which I don't see people usally use this hack which is very cool thing to use and I am sure your going to use this hack on daily basis.
So, Lets assume that you have type ready for a object which is complex.
type Address = {
street: string;
city: string;
state: string;
country: string;
zip: string;
};
export type CompanySize =
| "0-20"
| "20-50"
| "50-100"
| "100-200"
| "200-500"
| "500-1000"
| "1000-2000"
| "2000+";
export interface OrganizationForm {
name: string;
description?: string;
address: Address;
contactEmail: string;
phoneNumber: string;
website: string;
industry: string;
size: CompanySize;
interests: string[];
techStack: string[];
}
export interface OrganizationState {
formData: OrganizationForm;
currentStep: number;
isLoading: boolean;
error: string | null;
successMessage: string | null;
}
export interface OrganizationActions {
setField: <K extends keyof OrganizationForm>(
key: K,
value: OrganizationForm[K]
) => void;
}
export interface OrganizationAsyncActions {
createOrganization: () => Promise<void>;
}
Then you want to create a default state or something a intial object with the type.
Usually you would go type all the properties and their default values. If your a person who is little smart would use suggestion or intellisense(like the ctrl+space) to fill in the properties.
But we have now more smarter way to do it thats all about this blog.
We can use a Ctrl+. shortcut to open the quick fix option and there another option called fill properties. This would instantly fill the object with default properties.
Conclusion
Yeah Yeah Yeah… VS Code is full of surprise starting from the emmet to various features like this. Untill I find another hack goodbye.
Linkedin: https://www.linkedin.com/in/harish-kumar-418a47237/
Github: https://github.com/harish-20
Top comments (0)