我将 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 中创建函数类型的正确方法是什么?
我想使用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)