Describe the bug
I'm currently working with tapi.js to parse API response and create new class instance with ease 🙂
However, when I use tapi with classes that extend an abstract class, the class returned by the builder is the abstract class and not the concrete class.
To Reproduce
https://stackblitz.com/edit/typescript-t4ibg5?devToolsHeight=33&file=index.ts
Expected behavior
I'd expect that builder return concrete class instance.
Environment (please complete the following information):
- tapi version v0.4.2
- node version v18.9.0
Typescript config file(s):
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"experimentalDecorators": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
Additional context
I have a little trouble with prototype inheritance in JS, but from what I understand :
When I call Object.getPrototypeOf(Admin)
, the prototype of UserObject
is returned.
So in the BuildableResource.ts
file, when tapi gets the constructor like this: Admin.constructor.prototype.constructor
, this is where the UserObject
is returned.
I'm actively looking for a solution and will come back to post it if I find one, but in the meantime I'm posting the issue because the problem might be with my class definitions? In any case several pairs of eyes are better than one 😅
Thanks!