'TypeError: Object prototype may only be an Object or null: undefined
Below if I import Entity I get the posts's subject error (TypeError: Object prototype may only be an Object or null: undefined), but if I replace the import with the actual Entity declaration the code runs fine.
This is Customer.ts in the form that produces the error when I run the code with ts-node:
index.ts
export { Customer } from "./Customer";
export { Entity } from "./Entity";
Customer.ts
import { Entity } from "./index";
export class Customer extends Entity {
sku: string;
constructor(po: any) {
super();
this.sku = po.sku;
}
}
Entity.ts
export abstract class Entity {
id?: string;
}
Run.ts (The test code)
import {Customer} from "./";
let c = new Customer({
name: "Bob"
});
console.log(c);
If I replace the Entity import with the declaration like this:
export abstract class Entity {
id?: string;
}
export class Customer extends Entity {
sku: string;
constructor(po: any) {
super();
this.sku = po.sku;
}
}
Then Run.ts logs this:
Customer { sku: undefined }
In other words it runs fine and produces no errors. Thoughts?
Solution 1:[1]
This is not directly an answer to the example above, but I got the same error message when I had Vue and Parcel, and this kind of code:
class Proxy {}
class MyProxy extends Proxy {}
After some lengthy debugging, it turned out that there seems to be some class name conflict with the name "Proxy", maybe from Parcel. After I renamed the super class as "AbstractProxy" or anything else than "Proxy", it started to work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PHZ.fi-Pharazon |
