Just recently, I delved into TypeScript and attempted to convert a JavaScript code to TypeScript while incorporating more object-oriented features. However, I encountered an issue when trying to execute it with cmd using the ns-node command.
private username:string;
^
TypeError: Object prototype may only be an Object or null: undefined
This error seemed puzzling, so I resorted to searching online for solutions. Despite trying various suggestions from different sources, none of them resolved the issue.
Here's a snippet of my code:
import { Entity } from './Entity';
import { Bullet } from './Bullet';
import * as fs from "fs";
export class Player extends Entity{
private username:string;
protected pressingRight:boolean ;
protected pressingLeft:boolean ;
...
}
Can anyone pinpoint what might be causing this problem? Your assistance is greatly appreciated.
EDIT:
import {Point} from "./Point";
import {Bullet} from "./Bullet";
import {Player} from "./Player";
export class Entity{
protected x:number;
protected y:number;
protected spdX:number = 0;
protected spdY:number = 0;
protected id:number;
protected map:string;
protected static initPack = {player:[],bullet:[]};
protected static removePack = {player:[],bullet:[]};
constructor(x:number,y:number,id:number,map:string){
this.x = x;
this.y=y;
this.id=id;
this.map=map;
}
...}
Additionally, here is the content of Bullet.ts :
import {Entity} from './Entity';
import {Player} from './Player';
export class Bullet extends Entity{
private angle:number;
private parentID:number;
private timer:number = 0;
private toRemove:boolean=false;
public static list={};
constructor(x:number,y:number,map:string,parentId:number,angle:number,id:number){
super(x,y,id,map);
this.angle = angle;
this.spdX= Math.cos(angle/180*Math.PI) * 10;
this.spdY= Math.sin(angle/180*Math.PI) * 10;
this.parentID = parentId;
Bullet.list[this.id] = self;
Bullet.initPack.bullet.push(this.getInitPack());
}