Include TypeScript in the mdBook page

To use TypeScript in the mdBook, it is a good idea to put TS snippets in to separate .ts files and include them in the page. The advantage of this is that we get IDE TypeScript language support, which is critical for learning and debugging TypeScript.

Version

if (ts) {
    const output = document.getElementById('version_output')! as HTMLPreElement;
    output.innerHTML = `
  ts.version: ${ts.version}
  `
}

number test

{
    let num: number = 123;
    const output = document.getElementById('number_output')! as HTMLPreElement;
    output.innerHTML += JSON.stringify({ num });
}

greeter test

{
    interface Person {
        firstName: string;
        lastName: string;
    }

    function greeter(person: Person) {
        return "Hello, " + person.firstName + " " + person.lastName;
    }

    let user = { firstName: "Jane", lastName: "User" };
    {
        const output = document.getElementById('greeter_output')! as HTMLPreElement;
        output.textContent += greeter(user);
    }
}