This line of code
export default memo(LoadingOverlay);
Run Code Online (Sandbox Code Playgroud)
Gives flow error
Missing type annotation for `P`. `P` is a type parameter declared in function type [1] and was implicitly instantiated at call of `memo` [2].Flow(InferError)
Run Code Online (Sandbox Code Playgroud)
And this line
export default memo<TProps>(LoadingOverlay);
Run Code Online (Sandbox Code Playgroud)
Gives compile time error.
What's the proper use of React memo with flow?
EDIT:
Here is the full file example
// @flow
// React modules
import React, { memo } from 'react';
// Material UI components
import Checkbox from …Run Code Online (Sandbox Code Playgroud) 我把我的global.d.ts文件放在src这样的文件夹中
declare global {
interface Window {
config: {
url: string;
};
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的组件中的某个地方做
window.config = 'x';
Run Code Online (Sandbox Code Playgroud)
并ts显示此错误
Error:(10, 22) TS2339: Property 'config' does not exist on type 'Window'.
Run Code Online (Sandbox Code Playgroud)
create-react-app 用于此应用程序。
"react-scripts": "3.0.1",
"typescript": "3.5.3"
Run Code Online (Sandbox Code Playgroud)
这是tsconfig.json看起来像
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve" …Run Code Online (Sandbox Code Playgroud) 我刚刚通过 github 安装了一个不在 npm 注册表中的软件包,就像这样
yarn add git+https://github.com/azazdeaz/react-color-picker-wheel.git
Run Code Online (Sandbox Code Playgroud)
现在我可以像这样在我的 package.json 文件中看到它
"react-color-picker-wheel": "git+https://github.com/azazdeaz/react-color-picker-wheel.git"
Run Code Online (Sandbox Code Playgroud)
但是,当我像这样导入时
import ColorPickerWheel from 'react-color-picker-wheel'
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
Uncaught Error: Cannot find module 'react-color-picker-wheel'
所以我在git中分叉了一个包.做了我的改变.然后在我的终端
npm install --save git+https://github.com/hayk94/ddp.js.git
Run Code Online (Sandbox Code Playgroud)
然后我尝试在我的代码中导入包
import DDP from 'ddp.js'
Run Code Online (Sandbox Code Playgroud)
但是webpack给了我这个错误
ERROR in ./main.js
Module not found: Error: Can't resolve 'ddp.js' in '/Users/hayksafaryan/projects/b2cEmbedLib'
@ ./main.js 23:11-28
@ multi (webpack)-dev-server/client?http://localhost:8080 babel-polyfill ./main.js
webpack: Failed to compile.
Run Code Online (Sandbox Code Playgroud)
但是,如果我从npm安装包,webpack工作正常.我在文档中导入包,但是对于git安装包可能有其他方法吗?
我怎么能按元素块数组?
例如,lodash具有此功能,按长度分块数组
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]
Run Code Online (Sandbox Code Playgroud)
所以我有一个这样的数组['a','b','*','c']我可以做类似的事情
chunk(['a', 'b', '*', 'c'], '*')
Run Code Online (Sandbox Code Playgroud)
这会给我
[['a', 'b'], ['c']]
Run Code Online (Sandbox Code Playgroud)
它类似于字符串拆分数组
在这段代码中
document.addEventListener('keydown', (e: SyntheticKeyboardEvent<Document>) => {
if (e.ctrlKey && e.shiftKey && e.code === 'KeyE' && !this.state.envChangePopupOpened) {
this.openPopup();
}
});
Run Code Online (Sandbox Code Playgroud)
Flow给出了两个似乎不是这样的问题.
首先,它给出了这个神秘的信息:
Cannot call `document.addEventListener` because: Either string [1] is incompatible with enum [2]. Or string [1] is incompatible with enum [3]. Or `KeyboardEvent` [4] is incompatible with `SyntheticKeyboardEvent` [5] in the first argument. Or string [1] is incompatible with enum [6]. Or string [1] is incompatible with string literal `wheel` [7]. Or string [1] is incompatible with enum [8]. …Run Code Online (Sandbox Code Playgroud) 大家好,我有这个模块
import React, { Component } from 'react'
import EmailListItem from './EmailListItem'
import { createContainer } from 'meteor/react-meteor-data'
import { Emails } from '../../../../../imports/collections/emails/Emails'
class EmailList extends Component {
constructor (props) {
super(props)
this.state = {
selectedEmails: new Set(),
checked: false
}
}
handleSelectedEmails (selectedEmail, checked) {
let selectedEmails = this.state.selectedEmails
if (checked) {
selectedEmails.add(selectedEmail)
} else {
selectedEmails.delete(selectedEmail)
}
this.setState({selectedEmails})
console.log('selectedEmails', this.state.selectedEmails)
}
removeSelected () {
const selectedEmails = Array.from(this.state.selectedEmails)
Meteor.call('emails.remove', selectedEmails, (err, result) => {
if (err) console.log(err) …Run Code Online (Sandbox Code Playgroud) 尝试在 Koa 中使用打字稿。
koa-respond并且@koa/cors没有@types包,所以我ambient-types.d.ts在我的 src 中添加了一个带有这些声明的文件
declare module 'koa-respond'
declare module '@koa/cors'
Run Code Online (Sandbox Code Playgroud)
但是我仍然从 ts 得到这些错误
Try `npm install @types/koa__cors` if it exists or add a new declaration (.d.ts) file containing `declare module 'koa__cors';`
src/server.ts(7,26): error TS7016: Could not find a declaration file for module 'koa-respond'. '/home/hayk/projects/learning/koa/koala/backend/node_modules/koa-respond/lib/koa-respond.js' implicitly has an 'any' type.
Try `npm install @types/koa-respond` if it exists or add a new declaration (.d.ts) file containing `declare module 'koa-respond';`
Run Code Online (Sandbox Code Playgroud)
这是我的 tsconfig.json
{
"compilerOptions": …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用immer https://github.com/mweststrate/immer作为我的减速器,但从打字稿中收到以下错误
Argument of type 'ReadonlyArray<IBidding>' is not assignable to parameter of type '(this: DraftArray<IBidding>, draftState: DraftArray<IBidding>, ...extraArgs: any[]) => void | Rea...'.
Type 'ReadonlyArray<IBidding>' provides no match for the signature '(this: DraftArray<IBidding>, draftState: DraftArray<IBidding>, ...extraArgs: any[]): void | ReadonlyArray<IBidding>'.
Run Code Online (Sandbox Code Playgroud)
我有types.ts这样的
export interface IBidding {
readonly id: string
readonly ownerId: string
readonly name: string
readonly description: string
readonly startDate: Date
readonly endDate: Date
readonly suppliers: ReadonlyArray<ISupplier>
readonly inquiryCreator: string
readonly bidStep: number,
readonly bids: ReadonlyArray<IBid>,
readonly …Run Code Online (Sandbox Code Playgroud) 我做了一个反应材料 ui AppBar。
有徽标和标签。
选项卡应位于 AppBar 的中心,徽标位于左侧。
但我无法让徽标移至左侧。
我怎样才能使它向左走?
我正在使用 mui 的网格系统,但如果有更好的解决方案并不重要。
这是一个实例https://codesandbox.io/embed/delicate-feather-mmf3k
const Header = () => {
const classes = useStyles();
const [value, setValue] = React.useState(0);
return (
<nav className={classes.root}>
<AppBar position="static" color="default">
<Toolbar style={{ alignItems: "center", justifyContent: "center" }}>
<Grid justify={"center"} alignItems={"center"} container>
<Grid style={{ justifySelf: "flex-start" }} item>
<img
className={classes.logo}
src={
"https://upload.wikimedia.org/wikipedia/commons/a/a7/React-icon.svg"
}
alt="Logo"
/>
</Grid>
<Grid item>
<Grid container justify={"center"}>
<Tabs
onChange={(e, v) => setValue(v)}
value={value}
aria-label="Navigation Tabs"
>
<Tab label={"page 1"} />
<Tab …Run Code Online (Sandbox Code Playgroud)