I’ve been using the following:
var modal = {
content: '',
form: '',
href: ''
}
But now I have started to use Typescript is there a better way I can declare an object and how can I declare the types of my properties. The reason I am using this object is that it’s inside of a function and inside that function I have other functions that set and use the values of the properties. Is this the best way for me to do this or is there another way I could better do this with typescript?
I guess you are looking for something like this:
Notice you don’t need to declare the variable
modalto be of typeModal, TypeScript will infer this information automatically. Just adding the type to the functions is sufficient.But if you like you could also make this type information explicit for the variable: