I am building a Site that can handle Users and Tasks. Now that I want to test the Tasks I get this error. I want to make a list of different tasks But I cant seem to import them properly.
When I autoImport from the IDE it does not help either.
This is my main.ts
import {SubTask,Task,SubTaskOne} from "./Task/Task";
const task1 = new Task('ersterTask')
const task2 = new Task('zweiterTask')
const task3 = new SubTask("subTask1", task1)
const task4 = new SubTaskOne("subTask2", task2, 1)
const tasks = [task1, task2, task3, task4];
tasks.forEach(task =>{
task.printTask
})
this is my Task.ts file
export interface ITask{
taskName: string;
printTask():void
}
export class Task implements ITask{
constructor(taskName: string) {
this.taskName = taskName;
}
taskName: string;
printTask() {
console.log(this.taskName);
}
}
export class SubTask extends Task implements ITask {
parentTask: Task;
constructor(taskName: string, parentTask: Task) {
super(taskName);
this.taskName = taskName;
this.parentTask = parentTask;
}
printTask() {
super.printTask();
console.log(this.parentTask);
}
}
export class SubTaskOne extends SubTask implements ITask {
taskId : number;
constructor(taskName: string, parentTask: Task, taskId: number) {
super(taskName, parentTask);
this.taskName = taskName;
this.parentTask = parentTask;
this.taskId = taskId;
}
printTask() {
super.printTask()
console.log(this.taskId);
}
}
When I execute i get this:
'Uncaught SyntaxError: ambiguous indirect export: SubTaskOne'
I am using typescript and Vite
this is my package.json:
{
"name": "tdd",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"test": "jest"
},
"devDependencies": {
"@types/jsdom": "^21.1.3",
"jest": "^29.6.1",
"jest-localstorage-mock": "^2.4.26",
"jsdom": "^22.1.0",
"ts-jest": "^29.1.1",
"typeorm": "^0.3.17",
"typescript": "4.5.2",
"vite": "^4.4.0",
"ts-node": "10.7.0",
"@types/node": "^16.11.10"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"transform": {
"node_modules/variables/.+\\.(j|t)sx?$": "ts-jest"
},
"transformIgnorePatterns": [
"node_modules/(?!variables/.*)"
],
"resetMocks": false,
"setupFiles": [
"jest-localstorage-mock"
]
},
"dependencies": {
"axios": "^1.4.0",
"typeorm": "0.3.17",
"reflect-metadata": "^0.1.13",
"pg": "^8.4.0",
"express": "^4.17.2",
"body-parser": "^1.19.1"
}
}
edit: even after putting the tasks in different files it did not work import looks like this now:
import {Task as Task} from "./Task/Task";
import {SubTask} from "./Task/SubTask";
import {SubTaskOne} from "./Task/SubTaskOne";