We also got module here now module is an optional Skip for now because it really makes sense once we
learn about modules in typescript and how we can connect multiple files.
So let's ignore that for now.
Lib is an interesting one though.
Lib is an option that allows you to specify which default objects and features typescript notes.
With that I mean things like working with the DOM let's say integrate [REMOVED] we have a button and on
the button we say Click me and when we click this button we just want to print the message.
Now an apt yes we can select this button we can get access to this button with documented query selector
for example selecting the first button we find.
Now if we do that then this works we get no time code error here.
So if I go to my button and I add an event listener here I get an error here actually because typescript
doesn't know for sure whether we find a button here.
For now we can work around that with an exclamation mark after this line and I'll come back to what
exactly this does in a future.
It basically tells typescript Don't worry such a button will exist we will get a value here.
So now we can add a click event here and then to find some anonymous function maybe where a console
log clicked.
Now the interesting thing here is not so much that I had to add the estimation Mark as I said it will
come back to bed but that if I run CSC this just compounds now shouldn't types could complain that document
is unknown to it.
How does it noted we have such a document constant or variable available.
How does it know that even if we have that available that it holds an object which has a query selector
method.
How does it know that button is something which has an add event listener method.
How does types know all of that.
Now you might say of course is knows because in vanilla javascript this would be valid code but keep
in mind that when you write it types could code you don't necessarily write it for the browser.
You could be writing your no dress application with TypeScript and dare indeed.
This would all not work.
So the reason why this works is this lib option and as you see it's not even set here.
But if it isn't set then some defaults are assumed if it's not set the defaults depend on your javascript
target here and for iOS 6 it by default includes all the features that are globally available in years
6.
For example the Map object which is available in iOS 6.
Therefore it wouldn't complain if you use map.
So it assumes all these years 6 features which are made available globally in javascript that they are
available in types code as well.
And in addition it assumes that all DRM API is are available.
You'll find the detailed descriptions about all these options by the way in the official docs which
are linked in the lecture at the end of this module.
So long story short if the live options not set some defaults are assumed and these are typically the
defaults you need to have types to run in the browser so all the dorm API is and so on.
If we comment is in and I now compile everything idea forget an error because now by commenting it in
we don't have to default settings anymore.
Instead we now say hey please include some default libraries so some default type definitions you could
say which I will give you in disarray and as you see I'm not passing any description any profs any value
is here and then from what I'm saying to typescript now is hey regarding all the defaults you know please
take this into account and you know nothing.
So only if that's commented out that works because then types will assume some defaults.
If I set the defaults explicitly well then typescript of course adheres to what I'm setting here and
ends here for example it doesn't know document it doesn't even though the console here so therefore
we want to set this to more reasonable values.
And again if you will hit control space and here you get all the completion.
And for example there we could add Dom that's an identifier and there are some predefined identifiers
which types could understand.
Again you find a complete list in the official docs the docs for this option are attached to this lecture
as well.
So this is a identifier types could understands and it's an identifier which basically unlocks all the
DOM API and typescript.
So the typescript understands what you're doing there.
So now already you see it knows console it knows document and so on.
So now since we're working with next gen javascript we should also add two years six option so that
typescript also understands all globally available iOS 6 options and it's also a good idea to add DRM
ignorable and script host with that year we would unlock all the core javascript features you would
want to work.
And this by the way is the exact default setup you get when you set target to iOS 6 anyways.
So if you comment design and set it up like this you have exactly the same behavior as if you don't
specify lib at all.
Now here hero will commented in though and with that does will compile again setting this is a bit redundant
though.
Just want to explain what it does.