Build failure within --project but not regular build when using generic classes
See original GitHub issueBug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
I am trying to access <any> properties on a generic class with a library. The build fails when this code is within a project/library (--project
) but the exact same setup within an Angular app, it compiles with no errors.
Command (mark with an x
)
- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc
Versions
Repro steps
So create a library and a component within that library:
ng generate library questions
ng generate component question --project=questions
this is the content of the question.component.ts
:
import { Component, OnInit, Input } from '@angular/core';
import { QuestionBase } from 'questions/lib/question-base';
@Component({
selector: 'lib-question',
templateUrl: './question.component.html',
styleUrls: ['./question.component.css']
})
export class QuestionComponent implements OnInit {
@Input() field: QuestionBase<any>;
constructor() { }
ngOnInit() {
}
}
this is the content of question.component.html
:
<p>
test works!
{{field.type}}
</p>
this is the content of question-base.ts
(from https://angular.io/guide/dynamic-form#question-model)
export class QuestionBase<T> {
value: T;
key: string;
label: string;
required: boolean;
order: number;
controlType: string;
constructor(options: {
value?: T,
key?: string,
label?: string,
required?: boolean,
order?: number,
controlType?: string
} = {}) {
this.value = options.value;
this.key = options.key || '';
this.label = options.label || '';
this.required = !!options.required;
this.order = options.order === undefined ? 1 : options.order;
this.controlType = options.controlType || '';
}
}
This does not compile correct with errors below. However, this exact same component and class code within an angular app rather than “project”/“library”… it compiles fine.
Any help appreciated, please let me know if you need more info.
The log given by the failure
BUILD ERROR
projects/questions/src/lib/question/question.component.ts.QuestionComponent.html(1,4): : Property 'type'does not exist on type 'QuestionBase<any>'.
Error: projects/questions/src/lib/question/question.component.ts.QuestionComponent.html(1,4): : Property'type' does not exist on type 'QuestionBase<any>'.
Desired functionality
To compile with no errors, just like the regular build does.
Mention any other details that might be useful
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Any updates on this? The dynamic form tutorial in the Angular Docs doesn’t compile when adding --aot. It says ‘type’ doesn’t exist on type ‘QuestionBase<any>’
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.