Reader small image

You're reading from  Learn React with TypeScript - Second Edition

Product typeBook
Published inMar 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804614204
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Carl Rippon
Carl Rippon
author image
Carl Rippon

Carl Rippon has been in the software industry for over 20 years developing a complex lines of business applications in various sectors. He has spent the last 8 years building single-page applications using a wide range of JavaScript technologies including Angular, ReactJS, and TypeScript. Carl has also written over 100 blog posts on various technologies.
Read more about Carl Rippon

Right arrow

Questions

Answer the following questions to check what you have learned about TypeScript:

  1. What would the inferred type be for the flag variable in the following code?
    let flag = false;
  2. What is the return type in the following function?
    function log(message: string) {
      return console.log(message);
    }
  3. What is the type annotation for an array of dates?
  4. Will a type error occur in the following code?
    type Point = {x: number; y: number; z?: number};
    const point: Point = { x: 24, y: 65 };
  5. Use a type alias to create a number that can only hold integer values between and including 1 and 3.
  6. What TypeScript compiler option can be used to prevent the transpilation process when a type error is found?
  7. The following code raises a type error because lastSale can’t accept null values:
    type Product = {
      name: string;
      lastSale: Date;
    }
    const table: Product = {name: "Table", lastSale: null}

How can the Product type be changed...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learn React with TypeScript - Second Edition
Published in: Mar 2023Publisher: PacktISBN-13: 9781804614204

Author (1)

author image
Carl Rippon

Carl Rippon has been in the software industry for over 20 years developing a complex lines of business applications in various sectors. He has spent the last 8 years building single-page applications using a wide range of JavaScript technologies including Angular, ReactJS, and TypeScript. Carl has also written over 100 blog posts on various technologies.
Read more about Carl Rippon