小编ami*_*neh的帖子

类型“Session & Partial<SessionData>”上不存在属性“user”

我在 javascript 中有一个代码,我正在尝试将其转换为打字稿

route.get('/order', async(req,res) => {  
    var sessionData = req.session;
    if(typeof sessionData.user === 'undefined')
    {        
        res.redirect('/panel/login');
    }    
Run Code Online (Sandbox Code Playgroud)

这是我曾经在 js 中正常工作的一段代码,但现在我收到以下错误user

“会话和部分”类型上不存在属性“用户”

我假设我应该为sessionData变量和(req, res)参数添加类型,但我不知道应该为其分配什么类型。

PS:我知道这个问题看起来很重复,但我已经尝试过其他类似问题的解决方案,但没有用

任何帮助,将不胜感激

javascript session node.js express typescript

11
推荐指数
2
解决办法
6780
查看次数

属性“insertId”在类型“Boolean |”上不存在 (Partial<TEvents> & { insertId?: 数字 | 未定义; })'

我有一段 JavaScript 代码,我正在尝试将其转换为 TypeScript

route.delete('/:id', async (req, res) => {
    try {
        const result = await events.delete(req.params.id);
        res.send({ success: true, data: { id: result.insertId } });
Run Code Online (Sandbox Code Playgroud)

这段代码过去在 js 中工作得很好,但现在我已将其转换为打字稿,我在 insertId 上收到此错误

Property 'insertId' does not exist on type 'Boolean | (Partial<TEvents> & { insertId?: number | undefined; })'. Property 'insertId' does not exist on type 'Boolean'.ts(2339)

我尝试通过在 TEvents 类型上添加 insertId 来解决问题,但它不起作用

这是我的事件模型:

import { Model } from './Model';
type TEvents = {
    total    ?:string;
    insertId ?:any;
    status   ?:any;
    id       ?:any; …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript

1
推荐指数
1
解决办法
529
查看次数

标签 统计

javascript ×2

node.js ×2

typescript ×2

express ×1

session ×1