我正在尝试为typescript中的React编写一个更高阶的函数:(1)需要被包装的组件的某些属性(2)允许在包装器上设置包装的组件属性(3)具有特定于包装器的属性 我基本上可以正常工作,但是当我在封装组件的匿名类上设置默认属性时,我从typescript中得到了一个我无法解决的错误。 我得到的错误是: src/withContainer.tsx:33:3 - error TS2322: Type 'typeof (Anonymous class)' is not assignable to type 'ComponentClass<P & Conta
我用这样的钩子从我的路线上得到匹配
const match = useRouteMatch('/chat/:id');
然后我想把它传递给子组件。但是当我把它传下来时,我得到了这个错误
Type 'match<{}> | null' is not assignable to type 'match<MatchParams>'.
在m子组件中,我正在这样做
import { RouteComponentProps } from 'react-router';
interface MatchParams {
我刚开始使用Typescript,不知道如何输入这种情况。我正在编写一个自定义钩子,并试图创建一个回调引用。我的问题是这个函数设置了ref的current,并且不返回任何东西,但是由于我将它用作ref,typescript对我大喊Property 'current' is missing in type '(node: any) => void' but required in type 'RefObject<HTMLDivElement>'。 提前谢谢你。 代码如下: import React, {useCallback,
我是d3的新手,我试着用d3、TypeScript和react实现一个最小的线条图。但是它总是会导致TypeScript错误。在我的图表被错误信息替换之前,我甚至会一刹那地看到它。
我尽可能地将d3部件从react代码中分离出来。有一个使用div呈现id的react组件,在componentDidUpdate中,id在一个单独的文件中传递给一个draw函数,其中包含所有的d3代码(下面的代码)。我试图为所有可以输入的内容提供一个类型。
import * as d3 from 'd3'
type Props = { id: string }
type Datum = {x: n
在我的项目中,我使用的是反应式打字本。对于状态管理,我使用的是React redux,对于函数处理,我使用的是redux-saga。为了粘合redux存储和函数,我使用了React的新钩子useSelector和useDispatch。我成功地提取了数据并能够在控制台中显示出来。。基于useSelector文档,我可以在不传递到状态的情况下呈现useSelector。当我映射useSelector的变量时,我得到了TypeScript错误:Object is of type 'unknown'. PS。我也是TypeScript中的新手。
这是我的反应功能组件
import R
我是TypeScript的新手。我希望传递类型记录的接口,以响应状态,然后呈现状态。但我不知道如何传递接口值来响应状态。
import React, { useState } from 'react'
export interface Person {
name: name
age: age
}
type name = "John"
type age = 30
const Test = () => {
const [state, setstate] = useState() //I want to pass the interface i
我的react项目中有这个错误输出
TypeScript error
Argument of type 'ReactNode' is not assignable to parameter of type 'ReactElement<any, string | JSXElementConstructor<any>> | ReactElement<any, string | JSXElementConstructor<any>>[]'.
Type 'undefined' is not assign
谢谢你花时间阅读这篇文章。
我正在尝试学习使用eslint和AirBnB配置一起使用react的类型记录。像映射对象数组和使用每个对象创建自定义函数组件这样简单的事情给了我下一个错误:
Argument of type '(product: ProductType) => JSX.Element' is not assignable to parameter of type '(value: object, index: number, array: object[]) => Element'.
下面是父组件ProductGrid:
const Pr
我正在使用create app+ typescript + eslint应用程序,在构建过程中有这样的错误:
Line 1:8: 'React' was used before it was defined @typescript-eslint/no-use-before-define
组件中的代码以以下代码开头:
import React from "react";
Eslint设置:
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
我使用了带类型脚本的react。我使用了一个更高阶的组件来检查用户是否通过了身份验证。在添加hoc之后,我在路由中得到如下错误 /home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/navigation/routes.ts
TypeScript error in /home/nidhin/Documents/Nidhinbackup/F/iot-remsys-demotwo/remsys/src/navigation/routes.ts(7,36):
Type 'Promise<typeof i
我得到了这个错误(还有其他错误): Type 'Dispatch<SetStateAction<null>>' is not assignable to type '() => void' 我基本上是这样做的: import React, {
ReactElement,
ReactNode,
useEffect,
useRef,
useState,
useContext,
} from 'react';
export const ScrollToContext = React.create
我试图在元素上发送单击事件,但是TypeScript不喜欢any并发出警告,所以我尝试使用React.MouseEvent<HTMLElement>,但是它会抛出一个错误。
`Property 'id' does not exist on type 'EventTarget'.`
const closeWindow = (e: React.MouseEvent<HTMLElement>) => {
if (e.target.id === 'modal-window') ...
}
return (
<
我是react-redux的新手。我有这个代码,我正在使用react,redux和TypeScript。在这段使用基于类的组件的代码中,我想使用dispatch来调用动作来增加counter的值,但这给了我以下错误。
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of Re
我对TypeScript很陌生,并试图了解如何将React代码转换为被键入的代码。目前,我得到了以下错误:
Property 'openMenu' does not exist on type '{ children?: ReactNode; }'
Property 'toggle' does not exist on type '{ children?: ReactNode; }'
Property 'slidein' does not exist on type '{ children?: ReactN