Giter VIP home page Giter VIP logo

beginners-typescript-tutorial's People

Contributors

aljadan avatar arnaudnyc avatar danielebaelde-rad avatar emnul avatar joelhooks avatar marekzelinka avatar mattpocock avatar mrxvt avatar mzaien avatar patrykmaron avatar suraj5969 avatar talves avatar vojtaholik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beginners-typescript-tutorial's Issues

Can not install packages and run project

I have cloned the project and tried to install packages. But I got the following error:

error F:\code\beginners-typescript-tutorial\node_modules\esbuild: Command failed.
Exit code: 1
Command: node install.js
Arguments:
Directory: F:\code\beginners-typescript-tutorial\node_modules\esbuild
Output:
node:internal/errors:841
const err = new Error(message);

Another solution for Exercise 02

type AddTwoNumbersArgs = {
  first: number;
  second: number;
};

type AddTwoNumbersFn = (params: AddTwoNumbersArgs) => number;

export const addTwoNumbers: AddTwoNumbersFn = (params) => {
  return params.first + params.second;
};

Idea for Markdown explanations of each solution

What about adding a corresponding markdown file for each lesson. This would essentially be what you would be saying if you were teaching it as you did on livestream.

01-number.problem.md

We need to tell Typescript what type of data are expect for parameters a and b in the addTwoNumbers function. The format to declare the type of a function parameter is to add : type following each parameter. In this case it would be : number. With this information, Typescript can go to work enforcing appropriate typing of the addTwoNumbers function parameters.

Even better, format the makdown file so that the top describes the problem/expectations and then a link scrolls down to describe the answer.

Exercise 08 can be solved without a `User` return type annotation

Providing a default user that matches the shape of User without actually providing a return type annotation passes the tests and typecheck, but that obviously avoids the intended lesson.

const makeUser = () => {
  return {
    id: 1,
    firstName: '',
    lastName: '',
    role: 'user',
    posts: [
      {
        id: 1,
        title: '',
      },
    ],
  }
}

Unhandled error when starting the course

There's an unhandled error when starting the course:

image

Running tests...
failed to load config from /home/projects/kkvioyjzk.github/vite.config.ts

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: The package "esbuild-linux-64" could not be found, and is needed by esbuild.

If you are installing esbuild with npm, make sure that you don't specify the
"--no-optional" flag. The "optionalDependencies" package.json feature is used
by esbuild to install the correct binary executable for your current platform.
    at generateBinPath (file:///home/projects/kkvioyjzk.github/node_modules/esbuild/lib/main.js:1843:15)
    at esbuildCommandAndArgs (file:///home/projects/kkvioyjzk.github/node_modules/esbuild/lib/main.js:1901:31)
    at ensureServiceIsRunning (file:///home/projects/kkvioyjzk.github/node_modules/esbuild/lib/main.js:2065:25)
    at Module.build (file:///home/projects/kkvioyjzk.github/node_modules/esbuild/lib/main.js:1956:26)
    at bundleConfigFile (file://file:///home/projects/kkvioyjzk.github/node_modules/vite/dist/node/chunks/dep-5cb728cb.js:62943:35)
    at loadConfigFromFile (file://file:///home/projects/kkvioyjzk.github/node_modules/vite/dist/node/chunks/dep-5cb728cb.js:62919:31)
    at resolveConfig (file://file:///home/projects/kkvioyjzk.github/node_modules/vite/dist/node/chunks/dep-5cb728cb.js:62534:34)
    at Module.createServer (file://file:///home/projects/kkvioyjzk.github/node_modules/vite/dist/node/chunks/dep-5cb728cb.js:59137:26)
    at createVitest (file://file:///home/projects/kkvioyjzk.github/node_modules/vitest/dist/chunk-node-pkg.30d8b37e.js:13867:30)
    at async Module.startVitest (file://file:///home/projects/kkvioyjzk.github/node_modules/vitest/dist/chunk-node-pkg.30d8b37e.js:20259:15)

Failed. Try again!

Episode 12 should not do both tests with the same number

const coerceAmount = (amount: number | { amount: number }) => {
  return 20;
};

it("Should return the amount when passed an object", () => {
  expect(coerceAmount({ amount: 20 })).toEqual(20);
});

it("Should return the amount when passed a number", () => {
  expect(coerceAmount(20)).toEqual(20);
});

Ex 12 can be passed with just returning 20, perhaps the tests should use two different numbers to make this work around less obvious?

Parameter 'a' implicitly has an 'any' type when attempting to run the first exercise

when i try to run the first exercise, I get the following error messages

Running tests...

 RUN  v0.21.1 /home/elementary/Downloads/beginners-typescript-tutorial

  src/01-number.problem.ts (1)

Test Files  1 passed (1)
     Tests  1 passed (1)
  Start at  14:16:57
  Duration  1.30s (setup 62ms, collect 27ms, tests 5ms)

Checking types...
src/01-number.problem.ts:3:31 - error TS7006: Parameter 'a' implicitly has an 'any' type.

3 export const addTwoNumbers = (a, b) => {
                                ~

src/01-number.problem.ts:3:34 - error TS7006: Parameter 'b' implicitly has an 'any' type.

3 export const addTwoNumbers = (a, b) => {
                                   ~


Found 2 errors in the same file, starting at: src/01-number.problem.ts:3

I've tried settings tsconfig.json's noImplicityAny' and strict` options to 'false' as advisable on the internet, but the error still persists. Any help?

Exercise 09 doesn't have a description nor instructions

First of all thank you for making this! It will definitely be helpful for a lot of people 🙌

I've just went through the exercises and in the number 9, I realized that there isn't any kind of description of the problem or hint on how to solve it. I guess it would probably be hard for a beginner to realize what should be done in that case.

I'd like to hear your thoughts on this.

How about adding `Partial` Example?

Hey @mattpocock .
Thanks for your effort and time spent on this course.
I'd suggest adding Partial Example.
What do you think of that?

/**
 * How do we make _only_ the id property mandatory?
 */
interface User {
  id: string;
  firstName: string;
  lastName: string;
  address: string;
  age: number;
  sex: string;
}

/**
 * Answer1 - optional properties
 */
interface User {
  id: string;
  firstName?: string;
  lastName?: string;
  address?: string;
  age?: number;
  sex?: string;
};

/**
 * Answer2 - Partial properties
 */
interface User {
  id: string;
} & Partial<{
  firstName: string;
  lastName: string;
  address: string;
  age: number;
  sex: string;
}>

Add a preferred node version

Hey!!

First of, thanks for the great and very useful initiative!

I would like to suggest adding a .nvmrc file to the project. The reason is that, on my case, I have an older node version installed and used by default. When trying to run the first exercise I would get this error:

  argv.passWithNoTests ?? (argv.passWithNoTests = true);
                        ^
SyntaxError: Unexpected token '?'

This is related to vite configs I guess, but since installing dependencies didn't throw any error took me a few minutes to realize it was the node version. Adding the preferred node version to the project would help to identify this earlier.

:)

@types/react-dom can't find exported member.

Hey!
Superconfusing error I get when I download the project and install it. When running the install and then an exercise I get this message:

image

../../../../node_modules/@types/react-dom/index.d.ts:20:19 - error TS2724: '"react"' has no exported member named 'SFCElement'. Did you mean 'CElement'

But I can't even find the @types/react-dom/index.d.ts file.

.vscode folder should probably be removed

Awesome project, can't wait to jump in.

Was confused when VS Code opened up in high zoom level with the nav bar on the right. I think it is best to not mess with user settings too much and just leave it up to the user. Maybe add the .vscode folder to .gitignore or something.

Thanks!

Problem 06-unions, backdoor

Hey @mattpocock .
Thanks for your effort and time spent on this course.
I just want to point out that you can fool typechecker in this exercise with simply typing this, and it will pass the test.
role: string[] instead of role: 'admin' | 'user' | 'super-admin'

No license file

The license file indicate how changes can be made to your repo. If included, it helps contributors know how you want pull requests and issues handled.

Possible alternative solution to problem 15-intersection

I came up with a slightly different solution to problem 15-intersection which follows from problem 14-extends.

interface UserWithPosts extends User {
  posts: Post[]
}

This interface also passes the type check and it creates a slightly different code completion on WebStorm (at least)
Screenshot 2022-12-20 at 23 25 58
Screenshot 2022-12-20 at 23 26 26

Vs the video solution using &
Screenshot 2022-12-20 at 23 34 10
Screenshot 2022-12-20 at 23 34 25

There is no massive difference between the 2 but I thought I'd mention it. I imagine using the & operator with type is like using the extends with interfaces. They do the same as far as I can tell.

Thanks a ton for the great content! :)

Issue in problem 10

What the solution suggests for problem 10, still fails for me with an error.

image

image

But adding the Set in the variable type itself works:

image

image

I don't really understand the issue, but if you want I could open a PR which fixes the test :)

Error TS1005 on Exercise 15 from Beginner's guide

👋 Hello,

On this page https://www.totaltypescript.com/tutorials/beginners-typescript/combining-types-to-create-new-types/solution
if I use as suggested at the end

type UserAndPosts = (): User & { posts: Post[] }

export const getDefaultUserAndPosts = (): UserAndPosts => {

instead of
export const getDefaultUserAndPosts = (): User & { posts: Post[] } => {

I got errors: src/15-intersection.problem.ts:16:23 - error TS1005: '=>' expected.

What is wrong with it?

False positive in 07-arrays problem

This could be construed as a tuple of type Post, but of course it's an array.

posts: [
{
id: 1,
title: "How I eat so much cheese",
},
],

It might be better to create an array example so it fails if a student set the user interface to [Post] which passes the type checks.

  posts: [
    {
      id: 1,
      title: "How I eat so much cheese",
    },
    {
      id: 2,
      title: "Why I don't eat vegetables",
    },
  ],

Exercise 07 provides no explanation of the problem

Possibly related to #3 (wrong explanation included?)

I think this exercise might warrant a comment above/within User that points out that some change should be made to User in order to resolve the type error, similar to the comment in 06 noting that changing the role property is the way to solve the problem.

Encouraging `unknown` type introduction before narrowing

Hi!

In the spirit of providing alternate solutions
for exercice 13 (entitled catch-blocks),
does it make sense to encourage possible introduction of

  • unknown type
  • guard clause for case when e variable inheriting
    from Error class so that it is handled
    as expected (with expectation provided by test assertion),
  • guard clause for case when e variable
    does not inherit from Error class?

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.