TypeScript 支持
分类 | 类型 |
---|---|
子元素 | React.ReactNode |
\- | React.ReactElement |
样式属性 | React.CSSProperties |
DOM事件 | React.SyntheticEvent |
大纲
- 为啥需要“类型检查”
- TypeScript
- 类型
- TypeScript 类型
- React 类型
- Hooks 类型示例
- 常用类型
- 类型定义
- 语法:类型注解
- 类型:正确性
- 数据结构的类型
- 函数参数及返回值的类型
- 校验:必填规则
- 类型检查(类型检查器)
- 类型推断
- 静态类型提示:编辑器中提供内联文档
- UmiJS 与 TypeScript
为啥需要“类型检查”
TypeScript
- https://zh-hans.react.dev/learn/typescript
- https://zh-hans.legacy.reactjs.org/docs/static-type-checking.html#typescript
类型
TypeScript 类型
interface
接口type
类型<T>
范型
- https://www.typescriptlang.org/zh/docs/handbook/
- https://devblogs.microsoft.com/typescript/
- TypeScript playground
React 类型
- @types/react
- @types/react-dom
- tsx
Hooks 类型示例
- useState
- useReducer
- useContext
- useMemo
- useCallback
- https://zh-hans.react.dev/learn/typescript#example-hooks
- https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/basic_type_example
常用类型
- 子元素
- React.ReactNode
- React.ReactElement
- 样式属性
- React.CSSProperties
- DOM 事件
- React.SyntheticEvent
@types/react
@types/react-dom
类型定义
类型注解
<Type>
类型 注解
类型检查
类型推断
静态类型提示
UmiJS 与 TypeScript
- @typescript/eslint