在使用typescript和react + redux时遇到问题
Could not find a declaration file for module 'react-redux'. '/home/andrew/miramir/src/js/node_modules/react-redux/lib/index.js' implicitly has an 'any' type.
正在尝试从react-redux获取提供程序
import { Provider } from 'react-redux';
我怎么才能修复它?谢谢
在我的项目中,我使用的是反应式打字本。对于状态管理,我使用的是React redux,对于函数处理,我使用的是redux-saga。为了粘合redux存储和函数,我使用了React的新钩子useSelector和useDispatch。我成功地提取了数据并能够在控制台中显示出来。。基于useSelector文档,我可以在不传递到状态的情况下呈现useSelector。当我映射useSelector的变量时,我得到了TypeScript错误:Object is of type 'unknown'. PS。我也是TypeScript中的新手。
这是我的反应功能组件
import R
我正在使用TypeScript和React / Redux。我正在尝试将类型添加到我的Redux状态。我知道foo将是null或一个数字。但是,当我将其设置为字符串作为测试时,它并没有出错: //这是正确的 type State = {
foo: number;
};
function reducers(state = initialState, action): State {
//
} //这是错误的 type State = {
foo: string;
};
function reducers(state = initialState, action): State
我用typescript阅读了redux的官方文档。https://redux.js.org/recipes/usage-with-typescript 我能够输入action、reducers、react组件等。但是当我尝试输入sagas时,我遇到了这个问题。 这是logIn函数。 function* logIn(action) {
try {
let email = action.payload.email;
let password = action.payload.password;
// Here is the code for login
我试图使用状态管理的redux来构建带有typescript的react应用程序,但我在应用程序组件上遇到了这个错误。
-app.tsx
import React from 'react';
import { Provider } from 'react-redux';
//import { Router } from "react-router";
import store from './redux/store';
import './App.css';
function App() {
retur
我一直在使用React/Redux/Redux-Thunk项目中的TypeScript,我不断遇到这样的问题:在connect组件之后,如果不强制转换它,似乎不可能合理地使用它,因为连接过程似乎无法向类型系统传达连接操作已经满足了一些或所有属性要求。例如,考虑以下组件/类型/等:
import * as React from 'react';
import {connect} from "react-redux";
import {Action, bindActionCreators, Dispatch} from "redux";
import
Failed to compile.
/app/node_modules/@ant-design/icons/lib/components/AntdIcon.d.ts
TypeScript error in /app/node_modules/@ant-design/icons/lib/components/AntdIcon.d.ts(2,13):
'=' expected. TS1005
1 | import * as React from 'react';
> 2 | import type { IconDefinition } from &
我正在使用react-redux钩子useSelector和TypeScript。是否支持静态类型?现在我必须使用as关键字进行转换。 interface User { age: number }
const selectUser = (state): User => state.user.detail
const MyComponent = () => {
const user1 = useSelector(selectUser)
user1.age = 'This is not number.' // No warning or erro
我遵循JavaScript中的redux教程,但是当我用TypeScript编写时,我无法将状态映射到道具。
App.tsx
import * as React from 'react';
import Todo from '../models/Todo';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import Main from './Main';
export interface State {