>> I'm, John Papa.
>> And I'm Anders Hejlsberg.
>> Today we're going to talk about
five things about TypeScript.
Thing one, why and when would we use TypeScript?
>> Well, TypeScript is
useful if you're writing JavaScript apps.
And the bigger the app you're
writing, the more useful it is.
It basically delivers two things,
excellent tooling, enabled by static typing,
and then the ability to use
modern JavaScript features on
down-level browsers through transpilation.
>> Why type in TypeScript?
If you don't have these types, right? They're optional?
>> They are optional, but, listen,
we all know that it's better to find errors
before the space shuttle flies
than whilst it's flying. Do you know what I mean?
>> Yes.
>> If anything, you could prove statically,
is better done statically than dynamically.
That's one thing. The other thing is tooling.
When you're writing code in JavaScript,
things like statement completion.
How do you get that in a dynamic programming language?
You don't know what x is, or when you say x dot.
I don't know, I'd show you
all the identifiers in the file or something,
but if you have
static types you can actually
deliver intelligent tooling.
You can deliver refactorings that are guaranteed to work.
You try to refactor a large JavaScript codebase
and it's literally impossible.
>> It is.
>> Once they get to a certain size,
they become read-only, if you will.
And all you can do is add more goop around them,
but they are not changed
like big things all
over the place. Do you know what I mean?
So, with TypeScript you can you can do
these large scale things to
your codebase and be productive.
And leave you to think about
the algorithms instead of doing all the grunt work.
>> I like to grunt, though. Is that okay?
>> That's okay.
>> All right, cool. I'll still use TypeScript.
>> That's all right.
>> Thing two. What are
the tools that you get by using TypeScript?
>> Well, with TypeScript you get
a compiler and a type checker.
And basically, the type checker
can check your JavaScript code statically,
using types that are in your code or types
that come in declaration files
that describe the frameworks that you're using.
And then it can show you places
where you're doing something wrong.
>> I'm doing something wrong?
>> Possibly.
The other thing is TypeScript can down-level
transpile your code,
so you can use the latest ECMAScript 2017 features,
yet, run your code on browsers that are
only ECMAscript 3 or ECMAscript 5 compliant.
Because for a lot of those new features,
they are sort of down-level representations
that you can generate instead.
>> And we can find bugs with
TypeScript at development time?
>> Yes.
>> Easier than we could,
I suppose, at two in the morning?
>> Sure. No, and that's the static type checking, right?
>> Right.
>> And then, of course, TypeScript integrates
into untold numbers of popular editors,
Visual Studio Code included.
In fact, we built TypeScript so that
the language service is retargetable,
and TypeScript is built in itself,
so it'll run anywhere that JavaScript runs.
So, if you can get to JavaScript from your editor,
then you can actually
implement and use the TypeScript language services.
And so, we have plugins for Visual Studio Code,
but also Sublime Text,
Atom, Vim, Emacs, you name it.
Pretty much any popular editor.
>> It's fantastic.
>> You can use the TypeScript toolset.
>> Awesome. Number three.
I've been doing JavaScript for 20 years.
You're now talking about TypeScript.
Who is this really for?
How would you convince me to use it?
>> Sure. Well, I think,
first of all, you could say it
depends on the size of your codebase.
If you're writing three lines of JavaScript
embedded in an HTML page or whatever,
then yeah, you probably don't need TypeScript.
But the larger your project gets,
and these projects always get larger,
the more useful it gets.
And it's pretty darn useful even for small stuff.
The ability to get aids,
like statement completion, and refactoring,
and code navigation or whatever,
even in a thousand line codebase, is super useful.
>> What's your breakpoint on
where it becomes useful? A couple files?
>> Well, like I said,
I think it's useful from day zero.
It's useful on a single line.
It's useful even if you don't
know that you're using TypeScript because
we use the TypeScript compiler and language service
even if you're editing in JavaScript and
Visual Studio Code, for example.
And then, because TypeScript is a superset of JavaScript.
JavaScript is, in a sense,
just TypeScript without type annotations.
Do you know what I mean?
But we have very strong type inference in our compiler,
so we can infer a lot of the types,
even if you didn't write them.
And if you, for example,
reference a particular node module and import it,
and then you say, "My module dot."
Well, if there's a declaration
file for it, we can go find it.
And then we can serve up
statement completion for you in a JavaScript file.
>> So, we're getting the benefits of
TypeScript even if we're not using TypeScript.
>> Exactly, it's the TypeScript technologies
that are behind that power.
>> Fantastic. Number four.
When using TypeScripts, if I'm not sure I want to use it,
can I walk away at any time? What's the catch there?
>> You pretty much can because
TypeScript is just JavaScript with type annotations.
And when you compile,
we compile the JavaScript.
And we actually labor really hard
to generate nice looking,
pretty JavaScript, all of your comments.
>> So, I would be proud of
the Javascript that comes out of it?
>> Well, a lot of people look at it and go,
"Well, this looks like JavaScript."
Well yes, because all we do
is erase the type annotations, if you will.
But if you're using newer features of ECMAscript,
we'll transpile them into old style ECMAscript.
But hey, you'd be doing that if you
were using Babel or something else as well.
So yes, you can walk away,
but I have to tell you,
I don't see a lot of people walking away.
But you can, for sure.
>> But it's good to know that you can use it,
you can transpile to any ES that you want.
>> Yes.
>> ES1?
>> ES3.
>> You don't want to go to ES1.
That'd put you back in the mid 90s.
>> Yes, it would. I don't want to go back
there. Although, I had hair back then.
Number five.
I want to get started,
where would you recommend we go?
>> Well, I would start at our typescriptlang.org,
our website, which has a bunch of quick starters,
documentation, demos, and also,
an interactive playground where you can type
TypeScript code and see what happens to it when
you compile it and see what errors we flag.
>> Side by side, right?
>> Side by side, yeah.
>> That's awesome.
>> And in fact, because TypeScript
is written in TypeScript,
meaning that it's JavaScript,
that playground runs in any browser,
it runs on your phone even, so yeah.
>> Have to try that out.
>> Yeah.
>> All right. Now, for a Twitter question.
I got this question on Twitter here from anonymous user.
How much does TypeScript cost?
>> Zero. It's an open-source project.
In fact, everything that we do in TypeScript,
that the whole team does, is on GitHub.
You can find us there everyday,
you can even ask us questions.
>> I've seen you there.
>> Or log bugs there.
Oh yeah, I know, I'm up there every day.
>> So, if people want to get in touch with you,
just go on to a GitHub issue and have a good yet.
>> Pretty much.
>> All right. Another question from the community.
How does the community also contribute to TypeScript?
>> Well, in many ways.
I think probably the most important one
is definitely Typed.
>> Definitely.
>> Which is this GitHub site that
collects type information for
all of the popular frameworks on the web.
And I think more than 4000 frameworks
now have coverage there.
And in a sense,
the open source community is writing
down the metadata for programming on the web,
and collecting it in DefinitelyTyped.
And all this information we could alter,
we can use, of course,
when you're coding in TypeScript.
But we can also use it in JavaScript because we use
the TypeScript technologies to
power our JavaScript language service.
So, if you're writing modern ECMAScript,
and you import some library,
if we can find the types for it on DefinitelyTyped,
then we can just auto
permission those and then give you state completion and
all documentation that describes
what the methods do and so forth.
So, it's a treasure trove and it's all been
created by the open source community
and it's just it's fantastic.
That is just sort of this virtuous cycle
that's going there, that I think is outstanding.
>> That's great. And that'll help us with VUE,
React, Angular or Azure APIs.
>> I think there's hardly a framework
today that doesn't have some form of coverage.
>> Definitely.
>> Yeah, definitely.
>> Well, thank you. I'm John Papa.
>> And I'm Anders Hejlsberg.
>> And we just learned five things about TypeScript.