microsoft / TypeScript-New-Handbook

Incubation repository for the new TypeScript handbook 🐣
MIT License
649 stars 27 forks source link

Running Code Samples #8

Open gcrev93 opened 4 years ago

gcrev93 commented 4 years ago

When selecting the 'Try' button and opening TypeScript playground (or simply copy and pasting the code locally), running some of the code samples does not allow users to see the results of the code (thinking in terms of beginners or those trying to get more of an understanding).

Suggestion: Update TS code samples to actually call functions created in code samples:

function printAll(strs: string | string[] | null) {
    if (typeof strs === "object") {
        for (const s of strs) {
            console.log(s)
        }
    }
    else if (typeof strs === "string") {
        console.log(strs)
    }
    else {
        // do nothing
    }
}

to

function printAll(strs: string | string[] | null) {
    if (typeof strs === "object") {
        for (const s of strs) {
            console.log(s)
        }
    }
    else if (typeof strs === "string") {
        console.log(strs)
    }
    else {
        // do nothing
    }
}

printAll("just wanna see something")
gautamsingal commented 4 years ago

Hey, @gcrev93 Just wanted to provide some feedback here. How about when we click on Try, rather than opening the URL, it runs the code there itself to show results. May be using iframe. That will help in not navigating away from the page. If not an iframe then maybe open up the link in a new tab. The idea behind is to make sure the user is not taken away from the handbook.

orta commented 4 years ago

We're probably gonna stick with sending folks to the playground in a new window when it moves to the website, getting a copy of the compiler and any deps to run the JS is about 8MB of downloads and just not worth the extra bandwidth when we can have it running in the playground