TypeScript Intermediate

Preview — 3 of 10 questions

What is a union type in TypeScript?

javascript
function format(value: string | number): string {
  return String(value);
}
AA type that merges two objects into one
BA type that converts values automatically between types
CA type that requires all properties from two interfaces
DA type that means the value can be one of several specified types

Inside the if block, what is the inferred type of value?

javascript
function process(value: string | number) {
  if (typeof value === "string") {
    return value.toUpperCase(); // what type is value here?
  }
  return value * 2;
}
Astring
Bstring | number
Cnumber
Dunknown

What properties must an object of type Employee have?

javascript
type Person = { name: string; age: number };
type Worker = { company: string; role: string };
type Employee = Person & Worker;
AAll four: name, age, company, and role
BEither name/age or company/role — intersection means "choose one"
COnly the properties that appear in both types
DNo properties — Employee is an empty type

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.