Git Product home page Git Product logo

typescript-workshop-exercises's Introduction

Introduction to TypeScript

Getting Started

Run:

npm install -g typescript@latest
npm install

Most of the exercises in this repo don't compile properly (it's your job to fix them!), but to make sure your environment is set up properly, start by running the Frankenstein script: npm run frankenstein

If this succeeds, you can continue with the exercises. You can run them in the same way you brought Frankenstein to life, e.g.: npm run variableTypes

Once you've completed the first file, replace the filename with the next test file and keep going.

Linting

TypeScript works best in conjunction with linting. If you haven't used it before, linting is like the green underline in a Word document - it isn't a typo (won't break your code), but there's an issue nonetheless and it's a good idea to fix it.

To run the linter in this project: npm run lint

Some of the things the linter picks up (that the TypeScript compiler doesn't) include:

  • Missing return type on a function
  • Explicit 'any' type used (instead of using 'any', try union types.)

typescript-workshop-exercises's People

Contributors

dependabot[bot] avatar katiewoolston avatar

Stargazers

 avatar

typescript-workshop-exercises's Issues

Error with the file 9_asyncFunctions.ts

Hi @katiewoolston. I fixed the code but with the following:


const  saveData = async (data: string) => {
  await new Promise((resolve) => {
    setTimeout(() => {
      console.log("saved data", data);
      resolve();
    }, 200);
  });
  return "success";
};

export const script = (): void => {
  saveData("some information");
};
script();

I get the following error msg: PS C:\Users\Admin\Downloads\typescript-workshop-exercises\scripts> npm run asyncFunctions

@ asyncFunctions C:\Users\Admin\Downloads\typescript-workshop-exercises
tsc scripts/9_asyncFunctions.ts && node scripts/9_asyncFunctions.js

scripts/9_asyncFunctions.ts:15:13 - error TS2585: 'Promise' only refers to a type, but
is being used as a value here. Do you need to change your target library? Try changing
the lib compiler option to es2015 or later.

15 await new Promise((resolve) => {
~~~~~~~

Found 1 error.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ asyncFunctions: tsc scripts/9_asyncFunctions.ts && node scripts/9_asyncFunctions.js
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ asyncFunctions script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Admin\AppData\Roaming\npm-cache_logs\2021-07-05T17_04_45_943Z-debug.log
PS C:\Users\Admin\Downloads\typescript-workshop-exercises\scripts>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.