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