This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Run Any Version of a Node Tool with npx

    John LindquistJohn Lindquist

    As node projects evolve, new features are added all the time. This results in different errors or results as you're migrating from one version to another. npx allows you to try out any version you want by simply adding the version number to the project you're using. This lesson covers using the TypeScript compiler through a different versions as async function support was added.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 Let's create a TypeScript file that has an async function in it, so async function foo, and then just write that out to an index file, so the entire contents of that file is just async function foo.

    00:13 With NPX, I can try out different versions. If I try out 1.6 of TypeScript and then pass in my file, you'll see that I get this specific error saying they're only available with ES6, and it's asking me to specify experimental async functions, so let's try with TypeScript 1.7.

    00:35 This time you see we get that first error, but we don't get that second error. That's only because we changed versions of TypeScript, which has change support for async functions over time.

    00:45 If we try with a much later version of TypeScript like 2.4, you'll see that it handles the async function just fine, and doesn't throw any errors. If I just try TypeScript without any version number in there, it'll use the latest version, and that won't produce any errors either.

    01:05 We can check the output, which would be index.js, and you'll see it compiled it down using that generator polyfill to support async functions. Or if you know that your browser supports async functions, you can always pass in command line arguments like target ES2017, pass in index.ts. Then our output would be the exact same file.

    Discuss

    Discuss