Skip to content
🔷

TypeScript 基础

150 道练习

150 道 TypeScript 练习覆盖类型标注、接口、泛型、联合类型与类型收窄,强化静态类型思维。

  1. 1

    Primitive 类型测验

    测试你的 knowledge 的 TypeScript primitive 类型 and identify 哪个是 不 primitive.

    单选题 简单
  2. 2

    类型 Annotation 语法

    Identify 正确语法 for 类型 annotation on 变量 in TypeScript.

    单选题 简单
  3. 3

    接口对比类型 Alias

    理解键 difference 之间接口 and 类型 alias for 对象 shapes.

    单选题 中等
  4. 4

    Union 类型测验

    测试你的理解的 union 类型 and 如何它们组合多个可能类型.

    单选题 简单
  5. 5

    Intersection 类型测验

    理解 intersection 类型 and 如何它们组合多个类型到 one.

    单选题 中等
  6. 6

    Enum 基础测验

    测试你的 knowledge 的 TypeScript enums and 它们的默认 numeric 值.

    单选题 简单
  7. 7

    Generics 基础测验

    理解 purpose 的 generics and 为什么它们是 used in TypeScript.

    单选题 中等
  8. 8

    类型 Guards 测验

    测试你的理解的 类型 guards and 如何它们 narrow 类型 at 运行时.

    单选题 中等
  9. 9

    可选 Chaining 测验

    理解如何可选 chaining (?.) 工作使用空 and undefined 值.

    单选题 简单
  10. 10

    Nullish Coalescing 测验

    测试你的 knowledge 的 nullish coalescing 运算符 (??) and 如何它 differs 从 ||.

    单选题 简单
  11. 11

    部分 Utility 类型测验

    理解什么部分<T> utility 类型做 到 existing 类型.

    单选题 中等
  12. 12

    Readonly 数组测验

    测试你的理解的 readonly 数组 and 什么操作是 prevented.

    单选题 中等
  13. 13

    Tuple 类型测验

    理解 tuple 类型 and 如何它们 differ 从 regular 数组.

    单选题 中等
  14. 14

    函数类型测验

    测试你的 knowledge 的函数类型 signatures in TypeScript.

    单选题 简单
  15. 15

    空对比 undefined 测验

    理解 difference 之间空 and undefined 返回类型.

    单选题 中等
  16. 16

    从不类型测验

    测试你的理解的 从不类型 and 当它 occurs.

    单选题 中等
  17. 17

    Unknown 对比任何测验

    理解 difference 之间 unknown and 任何类型 in TypeScript.

    单选题 中等
  18. 18

    类型 Assertion 测验

    测试你的 knowledge 的类型 assertions and 它们的语法 in TypeScript.

    单选题 简单
  19. 19

    Strict 模式测验

    理解什么 strict flag in tsconfig.JSON 启用.

    单选题 中等
  20. 20

    类型 Inference 测验

    测试你的理解的 如何 TypeScript infers 类型不使用 explicit annotations.

    单选题 简单
  21. 21

    Predict 类型 Annotation 输出

    Predict console 输出的 TypeScript program 使用类型 annotations.

    预测输出 入门
  22. 22

    Predict Union Narrowing 输出

    Predict 输出当 narrowing union 类型使用 typeof.

    预测输出 简单
  23. 23

    Predict Tuple Access 输出

    Predict 输出当 accessing 元素的 输入 tuple.

    预测输出 简单
  24. 24

    Predict Enum 值输出

    Predict numeric 输出的 TypeScript enum.

    预测输出 简单
  25. 25

    Predict 可选 Chaining 输出

    Predict 输出当 using 可选 chaining 使用空 对象.

    预测输出 简单
  26. 26

    Predict Nullish Coalescing 输出

    Predict 输出的 nullish coalescing 运算符使用各种值.

    预测输出 简单
  27. 27

    Predict 类型 Guard 输出

    Predict 输出当 using 用户-定义类型 guard 到 narrow 类型.

    预测输出 中等
  28. 28

    Predict Keyof 输出

    Predict 输出当 using keyof 到 extract 对象键.

    预测输出 中等
  29. 29

    Predict typeof Guard 输出

    Predict 输出当 using typeof for 类型 narrowing in 函数.

    预测输出 简单
  30. 30

    Predict instanceof 输出

    Predict 输出当 using instanceof for 类-based 类型 narrowing.

    预测输出 中等
  31. 31

    Predict Mapped 类型输出

    Predict 输出当 using mapped 类型到 transform 对象属性.

    预测输出 中等
  32. 32

    Predict Conditional 类型输出

    Predict 输出当 conditional 类型 resolves at 编译时间.

    预测输出 中等
  33. 33

    Predict 函数返回输出

    Predict 输出的 TypeScript 函数使用 explicit 返回类型.

    预测输出 简单
  34. 34

    Predict Generic Inference 输出

    Predict 输出当 TypeScript infers generic 类型参数.

    预测输出 中等
  35. 35

    Predict Const Assertion 输出

    Predict 输出当 using const assertion for literal 类型 inference.

    预测输出 中等
  36. 36

    Predict Satisfies 运算符输出

    Predict 输出当 using satisfies 运算符到 检查类型.

    预测输出 中等
  37. 37

    Predict Template Literal 输出

    Predict 输出当 using template literal 类型.

    预测输出 中等
  38. 38

    Predict Indexed Access 输出

    Predict 输出当 using indexed access 类型到 extract 属性类型.

    预测输出 中等
  39. 39

    Predict 选取 Utility 输出

    Predict 输出当 using 选取 utility 类型到 选择属性.

    预测输出 中等
  40. 40

    Predict 切换 Narrowing 输出

    Predict 输出当 using 切换语句 for 类型 narrowing 使用 discriminated unions.

    预测输出 中等
  41. 41

    Fill: 类型 Annotation

    完整类型 annotation for 变量那个存储数字.

    填空题 入门
  42. 42

    Fill: 接口属性

    完整接口属性 declaration 使用正确类型.

    填空题 简单
  43. 43

    Fill: Generic 函数

    完整 generic 函数 declaration 使用类型参数.

    填空题 中等
  44. 44

    Fill: 类型 Alias

    完整类型 alias declaration for union 的字符串 literals.

    填空题 简单
  45. 45

    Fill: Union 类型

    完整 union 类型 annotation using pipe 运算符.

    填空题 简单
  46. 46

    Fill: Tuple 类型

    完整 tuple 类型 declaration 使用正确语法.

    填空题 中等
  47. 47

    Fill: Enum 成员

    完整 enum declaration 使用字符串值.

    填空题 简单
  48. 48

    Fill: 类型 Guard

    完整用户-定义类型 guard 使用正确返回类型 predicate.

    填空题 中等
  49. 49

    Fill: Utility 类型

    完整 utility 类型那个制作所有属性可选.

    填空题 中等
  50. 50

    Fill: Mapped 类型

    完整 mapped 类型那个 converts 所有属性到 readonly.

    填空题 中等
  51. 51

    Fill: Conditional 类型

    完整 conditional 类型那个检查如果 T extends 字符串.

    填空题 中等
  52. 52

    Fill: Keyof 运算符

    完整类型那个 extracts 所有键 从对象类型.

    填空题 中等
  53. 53

    Fill: typeof Guard

    完整 typeof 类型 guard for narrowing 字符串.

    填空题 简单
  54. 54

    Fill: instanceof Guard

    完整 instanceof 类型 guard for narrowing 到类 类型.

    填空题 简单
  55. 55

    Fill: 类型 Assertion

    完整类型 assertion using as keyword.

    填空题 简单
  56. 56

    Fill: Satisfies 运算符

    完整类型检查 using satisfies 运算符.

    填空题 中等
  57. 57

    Fill: Const Assertion

    完整 const assertion 到获取 literal 类型.

    填空题 中等
  58. 58

    Fill: 可选属性

    完整接口使用可选属性.

    填空题 简单
  59. 59

    Fill: Readonly Modifier

    完整 readonly 数组类型 declaration.

    填空题 简单
  60. 60

    Fill: 函数类型

    完整函数类型 signature.

    填空题 简单
  61. 61

    查找: 类型 Mismatch

    查找类型错误 in 变量 assignment.

    找错误 简单
  62. 62

    查找: Missing 返回类型

    查找错误 in 函数那个 doesn't match 它的 declared 返回类型.

    找错误 简单
  63. 63

    查找: 错误 Generic Constraint

    查找错误 in generic 函数使用不正确类型 constraint.

    找错误 中等
  64. 64

    查找: 不正确类型 Assertion

    查找错误 in unsafe 类型 assertion.

    找错误 中等
  65. 65

    查找: Missing 类型 Guard

    查找错误哪里类型 guard 是需要但 missing.

    找错误 中等
  66. 66

    查找: 错误 Union 类型

    查找错误 in union 类型 usage.

    找错误 简单
  67. 67

    查找: 不正确接口

    查找错误 in 对象那个 doesn't match 它的接口.

    找错误 简单
  68. 68

    查找: Missing 可选属性

    查找错误当 accessing 可选属性不使用检查.

    找错误 中等
  69. 69

    查找: 错误 Tuple 类型

    查找错误 in tuple 那个 doesn't match 它的类型.

    找错误 中等
  70. 70

    查找: 不正确 Enum

    查找错误 in enum access.

    找错误 简单
  71. 71

    查找: Missing Readonly

    查找错误当 mutating readonly 数组.

    找错误 中等
  72. 72

    查找: 错误 Utility 类型

    查找错误当 using 错误 utility 类型.

    找错误 中等
  73. 73

    查找: 不正确 Mapped 类型

    查找错误 in mapped 类型那个 doesn't transform 正确地.

    找错误 中等
  74. 74

    查找: 错误 Conditional 类型

    查找错误 in conditional 类型那个 resolves 不正确地.

    找错误 中等
  75. 75

    查找: Missing 类型参数

    查找错误当 generic 类型参数是 不 provided.

    找错误 中等
  76. 76

    查找: 不正确类型 Narrowing

    查找错误 in 类型 narrowing 那个 doesn't 工作 as expected.

    找错误 中等
  77. 77

    查找: 错误函数 Overload

    查找错误 in 函数 overloads 那个 don't match implementation.

    找错误 中等
  78. 78

    查找: Missing 空检查

    查找错误当 accessing 属性不使用空 检查.

    找错误 简单
  79. 79

    查找: 不正确类型导入

    查找错误 in 类型-仅导入.

    找错误 中等
  80. 80

    查找: 错误 Strict 模式配置

    查找错误 caused 通过 strict 模式设置.

    找错误 中等
  81. 81

    概念: 类型 Safety

    检查你的理解的 什么类型 safety 平均值 in TypeScript.

    概念检查 简单
  82. 82

    概念: 为什么 TypeScript

    理解主要 benefits 的 using TypeScript over plain JavaScript.

    概念检查 简单
  83. 83

    概念: 结构输入

    理解 TypeScript's 结构 (duck) 输入系统.

    概念检查 中等
  84. 84

    概念: 类型 Erasure

    理解什么 happens 到 TypeScript 类型 at 运行时.

    概念检查 简单
  85. 85

    概念: 编译-时间对比运行时

    理解 distinction 之间编译-时间 and 运行时 in TypeScript.

    概念检查 中等
  86. 86

    概念: 类型 Widening

    理解类型 widening and 当 TypeScript generalizes literal 类型.

    概念检查 中等
  87. 87

    概念: Control Flow Analysis

    理解如何 TypeScript narrows 类型通过 control flow.

    概念检查 中等
  88. 88

    概念: Exhaustiveness 检查

    理解 exhaustiveness 检查使用从不类型 in 切换语句.

    概念检查 中等
  89. 89

    概念: Declaration 合并

    理解 declaration 合并使用接口.

    概念检查 中等
  90. 90

    概念: 类型对比接口

    理解当 到 use 类型 aliases 对比接口.

    概念检查 中等
  91. 91

    概念: 当到 Use Generics

    理解场景哪里 generics 是正确 choice.

    概念检查 中等
  92. 92

    概念: 类型 Inference Benefits

    理解 advantages 的 TypeScript's 类型 inference 系统.

    概念检查 简单
  93. 93

    概念: Strict 模式 Benefits

    理解 safety benefits 的 TypeScript's strict 模式.

    概念检查 中等
  94. 94

    概念: 迁移从 JS

    理解策略 for migrating JavaScript 到 TypeScript.

    概念检查 中等
  95. 95

    概念: tsconfig Importance

    理解 role 的 tsconfig.JSON in TypeScript 项目.

    概念检查 简单
  96. 96

    概念: 最佳实践

    理解键 TypeScript 最佳实践 for maintainable code.

    概念检查 中等
  97. 97

    概念: Soundness

    理解类型系统 soundness and 它的 limitations in TypeScript.

    概念检查 中等
  98. 98

    概念: 类型 Compatibility

    理解如何 TypeScript determines 类型 compatibility.

    概念检查 中等
  99. 99

    概念: Variance

    理解 variance in TypeScript's generic 类型.

    概念检查 中等
  100. 100

    概念: Declaration Files

    理解 purpose 的 .d.ts declaration files.

    概念检查 中等
  101. 101

    TS 用途

    TypeScript 的主要用途是什么?

    单选题 入门
  102. 102

    类型推断

    TypeScript 何时推断类型?

    单选题 入门
  103. 103

    接口与类型别名

    interface 和 type alias 有何区别?

    单选题 简单
  104. 104

    联合类型

    联合类型 A | B 是什么意思?

    单选题 入门
  105. 105

    交叉类型

    交叉类型 A & B 是什么意思?

    单选题 简单
  106. 106

    类型守卫用途

    什么是类型守卫?

    单选题 简单
  107. 107

    泛型用途

    TypeScript 中为什么用泛型?

    单选题 简单
  108. 108

    数字枚举

    此枚举产生什么?enum Direction { Up, Down, Left, Right }

    单选题 入门
  109. 109

    字符串枚举

    什么是字符串枚举?

    单选题 简单
  110. 110

    可选链

    可选链(?.)做什么?

    单选题 入门
  111. 111

    空值合并

    空值合并(??)做什么?

    单选题 入门
  112. 112

    元组类型

    TypeScript 中什么是元组类型?

    单选题 简单
  113. 113

    工具类型 Partial

    Partial<T> 做什么?

    单选题 简单
  114. 114

    工具类型 Pick

    Pick<T, K> 做什么?

    单选题 简单
  115. 115

    工具类型 Omit

    Omit<T, K> 做什么?

    单选题 简单
  116. 116

    工具类型 Readonly

    Readonly<T> 做什么?

    单选题 简单
  117. 117

    条件类型

    什么是条件类型?

    单选题 中等
  118. 118

    映射类型

    什么是映射类型?

    单选题 中等
  119. 119

    类型收窄

    什么是类型收窄?

    单选题 简单
  120. 120

    严格模式

    tsconfig 中 strict: true 启用什么?

    单选题 简单
  121. 121

    type 与 interface 选择

    何时应优先用 type 而非 interface?

    单选题 简单
  122. 122

    const 断言

    "as const" 做什么?

    单选题 中等
  123. 123

    判别联合

    什么是判别联合?

    单选题 中等
  124. 124

    函数重载

    TypeScript 中什么是函数重载?

    单选题 中等
  125. 125

    泛型约束

    泛型中 "T extends SomeType" 做什么?

    单选题 中等
  126. 126

    never 类型

    什么是 never 类型?

    单选题 中等
  127. 127

    unknown 与 any

    unknown 与 any 有何不同?

    单选题 中等
  128. 128

    类型断言

    什么是类型断言(as)?

    单选题 简单
  129. 129

    TS 编译

    TypeScript 编译器做什么?

    单选题 简单
  130. 130

    声明文件

    什么是 .d.ts 文件?

    单选题 中等
  131. 131

    数字类型推断

    预测输出。

    预测输出 入门
  132. 132

    const 字面量类型

    预测输出。

    预测输出 简单
  133. 133

    联合类型收窄

    预测输出。

    预测输出 简单
  134. 134

    枚举值

    预测输出。

    预测输出 入门
  135. 135

    字符串枚举值

    预测输出。

    预测输出 简单
  136. 136

    可选链 null

    预测输出。

    预测输出 入门
  137. 137

    空值合并零

    预测输出。

    预测输出 简单
  138. 138

    元组访问

    预测输出。

    预测输出 入门
  139. 139

    Partial 类型

    预测输出。

    预测输出 简单
  140. 140

    Pick 类型

    预测输出。

    预测输出 简单
  141. 141

    自定义类型守卫

    预测输出。

    预测输出 中等
  142. 142

    泛型 identity

    预测输出。

    预测输出 入门
  143. 143

    keyof 类型

    预测输出。

    预测输出 中等
  144. 144

    索引访问

    预测输出。

    预测输出 中等
  145. 145

    Readonly 属性

    预测输出。

    预测输出 简单
  146. 146

    条件类型结果

    预测输出。

    预测输出 中等
  147. 147

    判别联合收窄

    预测输出。

    预测输出 中等
  148. 148

    Omit 类型

    预测输出。

    预测输出 简单
  149. 149

    Record 类型

    预测输出。

    预测输出 简单
  150. 150

    switch 中的 never

    预测输出。

    预测输出 中等

动手做项目

通过引导式项目应用所学,含起始代码与解决方案。

查看项目