Build Your First TypeScript File
Video Lecture
Basic JavaScript File
Create yourself working a folder somewhere on your system.
mkdir tsbeginners
CD into it.
cd tsbeginners
And open VSCode
code .
In VSCode, create a new file called foo.js
1 2 3 4 5 6 7 |
|
We can run this file directly in Nodejs or include it in a web page, and it will run inside the browser. But this isn't typescript.
Test it,
node foo.js
The TypeScript Equivalent
Rename the foo.js to foo.ts
1 2 3 4 5 6 7 |
|
We can then compile it
tsc.cmd foo.ts
And then we can run it using Node.
node foo.js
The output will be
Hello, ABC
That is your very first typescript file.
Useful Links
ECMAScript Editions
https://www.w3schools.com/js/js_versions.asp
Metasyntactic Variables
I use metasyntactic variable names in this crash course.
Examples are foobar
, foo
, bar
, baz
, qux
, quux
, quuz
, corge
, grault
, garply
, waldo
, fred
, plugh
, xyzzy
, and thud
.
They don't mean anything special, they are just good for using in code examples.
https://en.wikipedia.org/wiki/Metasyntactic_variable
https://www.typescriptlang.org/docs/handbook/compiler-options.html