我正在努力解决当我使用作为包托管并通过 NPM Link 进行流式传输的自定义库时发生的 WebPack 错误。同时,量产版本运行完美
这是我的脚本
"scripts": {
"dev": "rm -rf build && NODE_ENV=development webpack",
"build": "rm -rf build && NODE_ENV=production webpack",
},
Run Code Online (Sandbox Code Playgroud)
当我使用构建脚本捆绑代码时,我得到
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 React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more …Run Code Online (Sandbox Code Playgroud) 我正在努力克服 TS 上的错误。
我根据我创建的 2 个接口(WalletInformationsEdit 和 UserInformationsEdit)定义值(在代码下面)
我遇到的问题是在数据库查询之后的行,值[字段]带有下划线:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'WalletInformationsEdit | UserInformationsEdit'.
No index signature with a parameter of type 'string' was found on type 'WalletInformationsEdit | UserInformationsEdit'.
Run Code Online (Sandbox Code Playgroud)
我找到了 2 个解决方案来避免此错误消息,但我不满意,因为它们使我的代码受到的保护较少:
1/ 在 TS 配置中,如果我取消 "strict": true 和 "noImplicitAny": true -> 工作
2/如果我用“任何”类型定义值,->工作
但我认为两者都不值得。
您对处理此案有什么建议吗?
提前致谢,
保罗
public async update(value: WalletInformationsEdit | UserInformationsEdit): Promise<any> {
try {
// saving id before …Run Code Online (Sandbox Code Playgroud) 我正在努力在我的 TS 项目中设置快速会话。当我进行基本设置(JS 方式)时,我创建了一个在每个 API 需求时调用的 MW,这样我就可以在会话中创建或不创建新的用户数组。
import {Request, Response, NextFunction} from 'express'
module.exports = (req: Request, res: Response, next: NextFunction) => {
console.log('session checker : ', req.session)
if (!req.session){
req.session.user = []
console.log('session initialized')
}
next();
}
Run Code Online (Sandbox Code Playgroud)
斗争在于 .user,TS 向我显示此错误
Property 'user' does not exist on type 'never'.
Run Code Online (Sandbox Code Playgroud)
你有办法克服它吗?
提前致谢,
保罗