[英]What does the colon after the function call mean in Native Starter Kit
Im trying to learn React Native and I am studying the code from the Native Starter Kit. 我正在尝试学习React Native,我正在研究Native Starter Kit中的代码。 I am having trouble understanding the following code.
我在理解以下代码时遇到了麻烦。 I understand the colon following a function call is usually a type definition of static type checkers like TypeScript as I use this in Angular projects, but as far as I can see, the starter project does not use anything like that.
我了解函数调用后的冒号通常是静态类型检查器(如TypeScript)的类型定义,因为我在Angular项目中使用了它,但据我所知,入门项目没有使用类似的东西。
Types file: 类型文件:
export type Action =
{ type: 'PUSH_NEW_ROUTE', route: string }
| { type: 'POP_ROUTE' }
| { type: 'POP_TO_ROUTE', route: string }
| { type: 'REPLACE_ROUTE', route: string }
| { type: 'REPLACE_OR_PUSH_ROUTE', route: string }
| { type: 'OPEN_DRAWER'}
| { type: 'CLOSE_DRAWER'}
| { type: 'SET_USER', name: string}
| { type: 'SET_LIST', list: string}
export type Dispatch = (action:Action | Array<Action>) => any;
export type GetState = () => Object;
export type PromiseAction = Promise<Action>;
Use case: 用例:
import type { Action } from './types';
export const SET_USER = 'SET_USER';
export function setUser(user:string):Action {
return {
type: SET_USER,
payload: user,
};
}
https://github.com/start-react/native-starter-kit https://github.com/start-react/native-starter-kit
package.json file: package.json文件:
{
"name": "NativeStarterKit",
"version": "6.1.0",
"private": true,
"scripts": {
"postinstall": "remotedev-debugger",
"start": "node_modules/react-native/packager/packager.sh",
"eslint": "eslint",
"test": "jest"
},
"dependencies": {
"color": "^0.11.3",
"lodash": "^4.13.1",
"moment": "^2.13.0",
"native-base": "2.1.1",
"react": "16.0.0-alpha.3",
"react-native": "0.43.1",
"react-native-code-push": "2.0.1-beta",
"react-native-easy-grid": "0.1.8",
"react-native-modalbox": "^1.3.4",
"react-native-router-flux": "3.38.0",
"react-redux": "^5.0.2",
"redux": "^3.6.0",
"redux-persist": "^4.0.0",
"redux-thunk": "^2.2.0",
"remote-redux-devtools": "^0.5.0"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
"babel-jest": "17.0.0",
"babel-preset-react-native": "1.9.0",
"chai": "^3.5.0",
"eslint": "^3.5.0",
"eslint-config-airbnb": "^11.1.0",
"eslint-plugin-import": "^1.14.0",
"eslint-plugin-jsx-a11y": "^2.2.1",
"eslint-plugin-react": "^6.2.0",
"eslint-plugin-react-native": "^2.0.0",
"jest": "17.0.0",
"jest-react-native": "17.0.0",
"mocha": "^2.5.3",
"react-test-renderer": "15.3.2",
"remote-redux-devtools-on-debugger": "^0.7.0",
"remotedev-server": "^0.1.2"
},
"keywords": [
"android",
"ios",
"react",
"native",
"react-native",
"native-base",
"native-modules",
"react-component",
"navbar",
"packager",
"rnpm",
"es6",
"redux",
"react-native-code-push",
"react-native boilerplate",
"react-native with redux",
"react-native with redux boilerplate",
"native-base boilerplate",
"react-native with native-base"
],
"upstreamRepo": "git@github.com:GeekyAnts/react-native-native-base-seed.git",
"jest": {
"preset": "jest-react-native"
}
}
Thanks. 谢谢。
It's static type checking using flow 使用流程进行静态类型检查
Check https://flow.org 检查https://flow.org
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.