-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: builds fail with Angular 5 and Angular CLI when @Type is used #108
Comments
Workaround is available angular/angular#20216 |
Same problem here |
Same problem with typescript 2.4.2 |
From the workaround mentioned in angular/angular#20216 class Type {
}
function getter() {
return Type;
}
class Foo {
@Type(getter)
public ofType;
} instead of : class Type {
}
class Foo {
@Type(() => Type)
public ofType;
} works |
Hi, same problem here, and thanks for the workaround, it works! want to know if there's gonna be a fix in next releases? |
@sandcake Can be made more universal, I came to this solution (this works on angular 5): export function serializeType<T>(object: T) {
return function () { return object; }
}
export class CatalogItem {
id: string;
@Type(serializeType(CatalogCategory))
category?: CatalogCategory = null;
@Type(serializeType(PackingVariant))
packing: PackingVariant;
price: string = null;
} |
@rmrevin I dont understand whats wrong any workaround? |
@istiti I don't understand your question |
Since angular5 cli1.5.4 i get same error « ...kind of undefined » due to decorator and I don’t understand your workaround comparing my case |
@istiti This solution for one particular case for the library class transformer. |
Have any one a workaround for @Transform decorator too? e.g.
raises the error of typescript too. @rmrevin Your solution works. Thanks! |
@okodo e.g.
|
I had the same issue with: Found a solution by changing typescript.js for now.
Which comes from here, if you compile typescript: |
Getting this problem with constructor(@Inject(APP_CONFIG) private config, private _http: HttpClient,
@Inject(forwardRef(() => AttributesService))
private _attributesService: AttributesService) Tried to do
Both resulted in runtime errors when trying to run in dev mode.. With the normal |
We need to wait until angular team fix this issue. For now solution to avoid this problem is following: @Type(forwardRef(() => Person) as any)
author: Person; |
I want to share my workaround that I put together after reading other advices here and there. It's patching an
Here's what changed, compared to the original file: https://github.com/kirillgroshkov/angular-cli/commit/18f14d71bc5d73dba488f8fc1d08fd46d1d885f1
|
Is there a solution for @Transform using forwardRef (or similar)? I don't like that we have to patch it, but at least, the forwardRef solution is just adding things within the same line, as opposed to having to create other constructs. I could use similar solution for @Transform, if possible. |
@pleerock any workaround when we have:
? Looks like forwardRefFn cannot have a parameter PS: @jpduckwo your solution is not working
|
I resolved upgrading typescript to 2.7, throwing away
|
Also not working in Angular class Test {
@Transform(
(value) => plainToClass(ApplicationData, JSON.parse(value)),
{ toClassOnly: true }
)
@Transform(
(value) => JSON.stringify(classToPlain(value)),
{ toPlainOnly: true }
)
data: ApplicationData;
} |
Yeah, for now, you need to put just function reference there:
translateUtcDateTime is a static method in another class |
ts 2.5 Not working class TransferType {
static stringify() {
return (value) => JSON.stringify(classToPlain(value));
}
static parse() {
return (value) => plainToClass(ApplicationData, JSON.parse(value));
}
}
export class Application {
@Transform(TransferType.parse(), { toClassOnly: true })
@Transform(TransferType.stringify(), { toPlainOnly: true })
data: ApplicationData = new ApplicationData();
} |
Pass the function reference, don't execute the function. |
Also problem remain class TransferType {
static stringify(value: string) {
return JSON.stringify(classToPlain(value));
}
static parse(value: string) {
return plainToClass(ApplicationData, JSON.parse(value));
}
}
export class Application {
@Transform(TransferType.parse, { toClassOnly: true })
@Transform(TransferType.stringify, { toPlainOnly: true })
data: ApplicationData;
}
export class ApplicationData {
@Type(() => User)
person: User;
@Type(() => Travel)
travel: Travel;
@Type(() => Consumption)
consumptions: Consumption[];
@Type(() => Additional)
additional: Additional;
} Oh, I same problem )) @type(() => ...) |
I don't think you can have two transforms over one field. Get one and extract the transform type from the parameter passed (second or third, don't remember), then react accordingly. |
Sorry for the late reply guys! Does this need fixing on our side? It seems for me this is a bug in the Angular compiler. |
Up |
This is an issue with Angular or project settings. Also, Angular 5 is not relevant anymore. If this happens in Angular 11 please open a new discussion. Please note that by default newer Angulars doesn't include |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
After upgrading to Angular 5 and Angular CLI 1.5.0, my production builds stopped working. It took me quite some time to figure out, that using the
@Type
decorator from class-transformer lead to the following error message when runningng build -prod
:As soon as I removed
@Type
, the build was working fine again. I have no idea where this has to be fixed, but hoped that maybe someone here knows what I can do to be able to use the latest Angular version with class-transformer.I have created a simple demo project here: https://github.com/philippd/angular5-ct
Just run
ng build -prod
to see the error.The text was updated successfully, but these errors were encountered: