TypeScript Advanced

Preview — 3 of 10 questions

What is the resolved type of IsString<number> and IsString<string>?

javascript
type IsString<T> = T extends string ? "yes" : "no";

type A = IsString<number>;
type B = IsString<string>;
ABoth are "yes"
BA is "yes", B is "no"
CBoth are string
DA is "no", B is "yes"

What does the Stringify<T> type produce when applied to Config?

javascript
type Stringify<T> = {
  [K in keyof T]: string;
};

interface Config {
  host: string;
  port: number;
  ssl: boolean;
}

type StringConfig = Stringify<Config>;
A{ host: string; port: number; ssl: boolean } (unchanged)
B{ host: string; port: string; ssl: string }
Cstring
DA union string | number | boolean

What is the type of ReturnType<typeof greet>?

javascript
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;

function greet(name: string): string {
  return `Hello, ${name}`;
}

type R = ReturnType<typeof greet>;
Anever
B(name: string) => string
Cstring
Dany

Sign up free to play

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