-
Show index.js
with tooltips etc
console.log('hello world')
> hello world
-
Show string indexOf
with a number - Salsa warnings but no errors, and output is -1
.
console.log('hello world'.indexOf(1))
> -1
-
Show string containing 1
succeeds.
console.log('hello 1 world'.indexOf(1))
> 6
-
Create a class with a single property, showing Code unable to inspect the types.
"use strict"
class Thing {
constructor() {
this._that = 'thing'
}
get That() {
return this._that
}
}
console.log(new Thing().That)
-
Rename the file to index.ts
and demonstrate the errors with the undefined property.
-
Create the property as string
.
class Thing {
_that: string
-
Build the project, and look for prompt to configure the tast runner.
-
Configure task runner and change the name of the file in args
to index.ts
.
-
Build the project and demonstrate the console complaining about ECMAScript 5 or higher. Show the new index.js
created, with es5
code.
-
Edit the build task and remove all arguments.
-
Create tsconfig.json
with "target": "es5"
, build & show the output and error, then set to es6
and show the error disappear.
-
Build the project to show it compiling.
-
Open index.js
to the side to show it when it recompiles every time.
-
Change the console.log
line so the private value is used, and build.
console.log(new Thing()._that + 1)
-
Change the property to be private
and demonstrate the error when building, but show the output, and it still running in node.
-
Create thing.ts
and move the class into it, and build.
-
Demonstrate F12
to jump to the class.
-
Run node and watch it fail:
console.log(new Thing().That + 1);
^
ReferenceError: Thing is not defined
-
Go to thing.ts
and add export class
and "use strict"
to export the class.
-
Go to index.ts
and import the class with import {Thing} from './thing'
.
-
Build and run, see node say SyntaxError: Unexpected token import
-
Explain that this is a feature not yet implemented in Node.js and set "module": "commonjs"
in tsconfig.json
.
-
Build and run. Output should work - show files.
-
Switch module types and explain that they can be used in browsers and with different module systems.
-
Show different combinations of target
and module
.