Reputation: 1161
So I started a new nest.js project, but I'm my eslint keep giving this error:
Type 'Task[]' is missing the following properties from type 'Task': id, title, description, statusts(2739)
I have a model.ts
export interface Task {
id: string;
title: string;
description: string;
status: TaskStatus
}
export enum TaskStatus {
OPEN = 'OPEN',
IN_PROGRESS = 'IN_PROGRESS',
DONE = 'DONE',
}
and a service on the same folder:
import { Injectable } from '@nestjs/common';
import { Task, TaskStatus } from './task.model';
import { v1 as uuidv1 } from 'uuid';
@Injectable()
export class TasksService {
private tasks: Task[] = [];
public getAllTasks(): Task {
return this.tasks; <- here
}
public createTask(title: string, description: string): Task {
const task: Task = {
id: uuidv1(),
title,
description,
status: TaskStatus.OPEN
};
this.tasks.push(task);
return task;
}
}
the method getAllTasks is returning the error
and this is my eslint file:
module.exports = {
'env': {
'es6': true,
'node': true
},
'extends': [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaVersion': 11,
'sourceType': 'module'
},
'plugins': [
'@typescript-eslint'
],
'rules': {
semi: [2, 'always'],
indent: ['error', 4],
"space-before-function-paren": 0,
"no-unused-vars": 0,
quotes: [2, "single", { "avoidEscape": true }]
}
};
I can't see any errors on this piece of code or if I'm supposed to set a new configuration on my eslint to avoid this.
Upvotes: 2
Views: 3198
Reputation: 381
private tasks: Task[] = [];
public getAllTasks(): Task {
return this.tasks; <- here
}
You are returning Task[]
in a function that expects to return Task
. I.e. change the return type to match getAllTask(): Task[] {
.
Upvotes: 3