小编Yus*_*bek的帖子

TypeScript 中函数类型参数的 ESLint 未使用变量规则

我将 ESLint 与 TypeScript 结合使用。当我尝试创建带有一些必需参数的函数类型时,ESLint 显示 error eslint: no-unused-vars

type Func = (paramA: number) => void这里,根据 ESLint,paramA 是未使用的变量。

我的.eslintrc.json档案

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "@typescript-eslint"
    ],
    "rules": {
    }
}
Run Code Online (Sandbox Code Playgroud)

那么,使用 ESLint 在 TypeScript 中创建函数类型的正确方法是什么?

javascript typescript eslint

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

Axios无法处理响应

我想使用Axios to React 将新文档发布到数据库。值得庆幸的是,我可以做到,但我也想在控制台上记录一条消息,指出“已插入新帖子”。

这是我的前端代码:

newTodo(todo){
axios.post('/todo', {
    title: todo.title,
    description: todo.description
  })
  .then(function (response) {
    console.log('New post has been inserted!');
  })
  .catch(function (error) {
    console.log(error);
  });
}
Run Code Online (Sandbox Code Playgroud)

我的后端(Nodejs)

server.post('/todo', (req, res) => {
    // Inserting new todo
    var newTodo = new todo({
        title: req.body.title,
        description: req.body.description,
        key: '',
        date: moment().format('lll')
    });

    newTodo.save((e, savedTodo) => {
        if(e){
            console.log(e);
        } else {
            todo.findById(savedTodo._id, (e, foundTodo) => {
                if(e) {
                    console.log(e);
                } else {
                    foundTodo.key = foundTodo._id.toString();
                    foundTodo.save((e, updatedTodo) => { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs axios

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

标签 统计

javascript ×2

axios ×1

eslint ×1

reactjs ×1

typescript ×1