← All topics

TypeScript Junior interview questions and answers

75 questions for a TypeScript (Junior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.What is TypeScript?
  2. 2.Does TypeScript check types while the program is running?
  3. 3.How does unknown differ from any?
  4. 4.What does the never type mean?
  5. 5.What type does TypeScript infer for let x = 5;?
  6. 6.What's the difference between interface and type for describing an object?
  7. 7.How do you declare an optional object property?
  8. 8.What does the readonly modifier do in { readonly id: number }?
  9. 9.What does the type string | number mean?
  10. 10.What does the intersection type Admin = User & { role: 'admin' } give you?
  11. 11.What is the literal type 'left' | 'right'?
  12. 12.How do you type a function that takes a string and returns a number?
  13. 13.How do you declare an optional function parameter?
  14. 14.What is a tuple in TypeScript?
  15. 15.How do you type an array of strings?
  16. 16.What is a generic?
  17. 17.What does the utility type Partial<User> do?
  18. 18.How do Pick<User, 'id' | 'name'> and Omit<User, 'password'> differ?
  19. 19.What does Record<string, number> describe?
  20. 20.What does keyof { id: number; name: string } return?
  21. 21.What does typeof do in a type position: type Config = typeof config?
  22. 22.What's the right way to type a React component's props?
  23. 23.What is the type of the event in onChange for an <input> in React?
  24. 24.How do you specify the state type if the initial value is null: useState(null)?
  25. 25.What does the type assertion value as string do?
  26. 26.What does the ! operator do in user!.name?
  27. 27.What does the strict flag in tsconfig.json enable?
  28. 28.What does strictNullChecks give you?
  29. 29.How do you narrow string | number to string inside a condition?
  30. 30.How does enum Color { Red, Green } differ from type Color = 'red' | 'green'?
  31. 31.What does as const do in const roles = ['admin', 'user'] as const?
  32. 32.What is structural typing in TypeScript?
  33. 33.What is a .d.ts file?
  34. 34.Why install packages like @types/lodash?
  35. 35.What does tsc compile a TypeScript file into?
  36. 36.What is the type of e in catch (e) with strict enabled?
  37. 37.What does the return type void mean?
  38. 38.How do you describe an object with arbitrary string keys and number values using an index signature?
  39. 39.How do you extend an interface?
  40. 40.What does implements do in a class?
  41. 41.How does private in TypeScript differ from #field in JavaScript?
  42. 42.How do you type an async function that returns a user?
  43. 43.What does TypeScript do with const el = document.getElementById('app')?
  44. 44.What is a union with a common discriminant field?
  45. 45.How do you get the return type of the createStore function?
  46. 46.What happens when you pass an object literal with an extra property?
  47. 47.What is tsconfig.json?
  48. 48.How do you gradually migrate a JS project to TypeScript?
  49. 49.How does Required<T> differ from Partial<T>?
  50. 50.How do you specify that a function accepts any number of numbers?
  51. 51.What does the noImplicitAny option report?
  52. 52.How does (string | number)[] differ from string[] | number[]?
  53. 53.What type does const direction = 'left'; get?
  54. 54.What is the type of users.find((u) => u.id === id) if users: User[]?
  55. 55.Why can typeof value === 'object' be a trap when narrowing?
  56. 56.What does if (count) miss when count: number | undefined?
  57. 57.How does instanceof help with types?
  58. 58.Why can't you check if (data is User) at runtime?
  59. 59.What does Readonly<User> do?
  60. 60.What does Record<'draft' | 'published', number> require?
  61. 61.What type does const items = []; get with strict enabled?
  62. 62.How do you call a generic function with an explicit type argument?
  63. 63.How do you write a reusable type for an event handler function?
  64. 64.Why can [1, 2].forEach((n) => console.log(n)) pass a callback with one parameter when forEach passes three?
  65. 65.What's the result type of user?.address?.city if city: string?
  66. 66.What is the type of const port = env.PORT ?? 3000 if env.PORT: string | undefined?
  67. 67.What type does await (await fetch(url)).json() have?
  68. 68.Which type should a React component use for children that may be text, elements or nothing?
  69. 69.Are Array<string> and string[] different types?
  70. 70.How do you check types in CI when a bundler (Vite, esbuild) already compiles TS without type checking?
  71. 71.How does an optional property name?: string differ from name: string | undefined?
  72. 72.How do you describe an object with a method in a type?
  73. 73.Can recent Node.js versions run a .ts file directly?
  74. 74.What type does a function parameter with a default value get?
  75. 75.Why is @ts-expect-error safer than @ts-ignore?