class-transformer: TypeError: Cannot read property 'prototype' of undefined
I am having three classes Person, BasicDetails and CloudResponse, when I extend BasicDetails class in Person class and then I run the following code it gives me error.
return this.http.post(Environment.domain, JSON.stringify(requestObj), {headers: this.headers})
.map((res: Response) => {
return res.json();
})
.map(res => plainToClass(MeraCRMCloudResponse, res as Object))
.catch((error: any) => Observable.throw(console.log(error)));
TypeError: Cannot read property ‘prototype’ of undefined at http://localhost:4200/main.bundle.js:60194:84 at Array.filter (native) at MetadataStorage.findMetadatas (http://localhost:4200/main.bundle.js:60194:46) at MetadataStorage.findTransformMetadatas (http://localhost:4200/main.bundle.js:60098:21) at TransformOperationExecutor.applyCustomTransformations (http://localhost:4200/main.bundle.js:59887:58) at _loop_1 (http://localhost:4200/main.bundle.js:59854:41) at TransformOperationExecutor.transform (http://localhost:4200/main.bundle.js:59876:31) at http://localhost:4200/main.bundle.js:59736:41 at Array.forEach (native) at TransformOperationExecutor.transform (http://localhost:4200/main.bundle.js:59733:19)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 25 (6 by maintainers)
Commits related to this issue
- fix class-transformer related issues see https://github.com/typestack/class-transformer/issues/28 — committed to vologab/nest by vologab 6 years ago
I made a naive fix long time ago in my fork. It worked in my situation, but I have no idea if it might have any implications somewhere else. https://github.com/britvik/class-transformer/commit/0a1144ce787ec04b19088a621f8e905b35852875
I thought I had a solution simply by using
@Typedecorators everywhere, but it didn’t always work. I still got this error when trying to useplainToClass, where the plain object contains extra fields that are complex objects.For now, I use the solution from @britvik (thanks!). But I prefere to keep using the original library instead of cloning it… So here’s my ugly patch, which I apply when my application starts :
I don’t know if it is going to work properly in the long run, but it seems to work for now. I wish @pleerock Iooks into this issue!
Just published
0.1.9, please test it and report if you still encounter this issue. Thanks!