#javascript #typescript
In this code we want every object pushed in to the addressBook
array to conform to the Contact
interface. When this is compiled to JavaScript this disappears, but this is helpful in development.
interface Contact { name: string, email: string, phone: string
} var addressBook: Contact[] = [];
If you want to change selection, open document below and click on "Move attachment"
Unknown titleTypeScript is clever enough to know the type of the myName variable.
Interfaces
Interfaces are great ways to set up agreements on the shape of object literals. Sometimes you just need to know the structure of a thing as a data store.
<span>In this code we want every object pushed in to the addressBook array to conform to the Contact interface. When this is compiled to JavaScript this disappears, but this is helpful in development.
interface Contact {
name: string,
email: string,
phone: string
}
var addressBook: Contact[] = [];
It can warn me in the method call of push if I don’t define the type on line 9.
Or if I specify the type on the variable declaration, it could warn me on line 9 that I’m missing Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details