[Flow] Declare types for application
2024-08-31 22:20:08
In Flow, you can make global declarion about types.
Run:
flow init
It will generate .flowconfig file, open it and add few lines of configration.
[libs]
decls/ [ignore]
.*/node_modules/.*
So it says that go to find 'decls' folders and use what has been defined as global type checking.
Declear a variable:
declare type PetAction = 'adopt' | 'foster';
Declear a function:
declare type PetShelterDispatch = (x: PetShelterActions) => void;
Declear an interface:
declare type Pet = {
name: string;
id: number;
from: string;
type: PetType;
locationId: number;
action?: PetAction;
};
All those will be global available for React components.
So you can use those, for example:
// @flow
module.exports = ([
{
type: 'dog',
name: 'Snoopy',
from: 'Charlie',
locationId: ,
id:
},
{
type: 'cat',
name: 'Garfield',
from: 'John',
locationId: ,
id:
}
]: Array<Pet>);
It is also good to declear type for "state", 'props':
// @flow const React = require('react'); type ModalProps = {
dispatch: PetShelterDispatch;
pet: Pet;
};
type ModalState = {
inquiry: ?PetInquiry;
}; class PetModal extends React.Component { props: ModalProps;
state: ModalState;
onSubmitClick: () => void; ....
最新文章
- spring-boot-framework 如何自动将对象返回成json格式
- android自定义viewgroup实现等分格子布局
- Spring的IoC容器注入的类型
- HDU 1425 sort 【哈希入门】
- Expat Parser解析xml文件
- 17、SQL Server 备份和还原
- Nmap功能与常用命令
- 入门VMware Workstation下的Debian学习之Vim简单使用(三)
- Qt 开发 MS VC 控件终极篇
- C语言程序设计(基础)- 第14、15周作业
- PHP中的反射模拟框架中控制器的调度
- JVM源码分析之SystemGC完全解读
- Mac 远程桌面 ubuntu16.04 unity
- ORM模型
- Steering Behaviors
- 【转】Java学习---内存泄露与溢出的区别
- Linq的简介和基础知识学习
- Idea多个module下maven的pom.xml失效的问题
- select2 选择框插件
- [one day one question] 有没有免费接收短信验证用于注册的软件或者平台?
热门文章
- Spring MVC框架实例
- JQuery 当点击input后,单选多选的选中状态
- solr6.3+tomcat8报错HTTP Status 403 – Forbidden解决办法
- JIRA6.3.6 安装汉化破解指南
- 支付宝支付返回通知时 notify_url和return_url的选择
- window.print()打印网页(一)
- LA 3135 - Argus
- C#实现自己主动升级(附源代码)
- php 面试题一(看视频的学习量比网上瞎转悠要清晰和明了很多)(看视频做好笔记)(注重复习)
- TEMPDB