- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我使用以下命令运行我的Reactjs + ElectronJS应用程序时,它可以很好地运行: yarn start 。
当我尝试使用以下命令生成该错误时: yarn build 。
我不明白这是怎么回事。
Property 'setUser' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'.
这是导致错误的代码:
export const test = () => ({
type: 'TEST',
});
export const setUser = (mail, pwd, token, firstname, lastname) => ({
type: 'SET_USER',
payload: {
Email: mail,
Pwd: pwd,
Token: token,
Firstname: firstname,
Lastname: lastname,
}
});
我在其他地方使用它来进行身份验证:
GetInfoFromBack() {
const param : any[] = [];
for (var i = 0; i < arguments.length; ++i) {
param[i] = arguments[i];
}
if (param[1] === null && param[2] != null) {
axios.get('http://104.xx.xx.192:xxxx' + param[0], param[2])
.then(response => {
if (param[0] === "/get_auth_user") {
this.props.setUser(response.data.email, this.props.base.Pwd, this.props.base.Token, response.data.firstname, response.data.lastname);
}
}).catch(err => {
alert(err.response.data);
})
} else {
alert("ERROR: bad request : " + param);
}
}
最佳答案
该错误与为组件上的props推断的类型有关。它回落到了React的props默认值。
两种情况相交以定义此默认值...Readonly<{}> & Readonly<{ children?: ReactNode; }>
a)没有 Prop 键
b)可能有一个 child Prop key (如果您通过JSX向元素添加了一些内容,例如标签,文本或渲染 Prop )。
要解决此问题,您需要明确说明组件消耗的 Prop 类型。
我相信从JSX typescript documentation可能最终看起来像这样,以确保对this.props的访问可以依赖于setUser函数...
import {
setUser
} from './myfile'
interface MyProps {
children: JSX.Element | JSX.Element[]
setUser: typeof setUser
}
class Component extends React.Component<MyProps, {}> {
render() {
return (
<h2>
{this.props.children}
</h2>
)
}
}
关于reactjs - 属性 'setUser'在 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'类型上不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63338023/
我正在我的一个项目上安装 Djaty Javascript SDK。现在已正确安装,我正在尝试使用 Djaty.setUser() 我想设置所有可能的用户信息,因此我在两个地方使用 Djaty.set
我有点迷失,希望得到任何帮助。我通过 userPhones 表在用户表和电话表之间建立了 M:M 关联。 user.js module.exports = (sequelize, DataType
我是一名优秀的程序员,十分优秀!