跳到主要内容

TypeScript 支持

分类类型
子元素React.ReactNode
\-React.ReactElement
样式属性React.CSSProperties
DOM事件React.SyntheticEvent

大纲

  • 为啥需要“类型检查”
    • TypeScript
  • 类型
    • TypeScript 类型
    • React 类型
      • Hooks 类型示例
      • 常用类型
  • 类型定义
    • 语法:类型注解
    • 类型:正确性
      • 数据结构的类型
      • 函数参数及返回值的类型
    • 校验:必填规则
  • 类型检查(类型检查器)
    • 类型推断
    • 静态类型提示:编辑器中提供内联文档
  • UmiJS 与 TypeScript

为啥需要“类型检查”

TypeScript

类型

TypeScript 类型

  • interface 接口
  • type 类型
  • <T> 范型

React 类型

  • @types/react
  • @types/react-dom
  • tsx

Hooks 类型示例

  • useState
  • useReducer
  • useContext
  • useMemo
  • useCallback

常用类型

  • 子元素
    • React.ReactNode
    • React.ReactElement
  • 样式属性
    • React.CSSProperties
  • DOM 事件
    • React.SyntheticEvent

@types/react

@types/react-dom

类型定义

类型注解

  • <Type> 类型注解

类型检查

类型推断

静态类型提示

UmiJS 与 TypeScript

  • @typescript/eslint