question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build failure within --project but not regular build when using generic classes

See original GitHub issue

Bug 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:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
ghtjiann4321commented, Oct 8, 2018

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>’

0reactions
angular-automatic-lock-bot[bot]commented, Sep 9, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error with Generics when compiling with Maven, but works ...
The class below belongs to the "core" module (sub-project): ... But, if I run the Maven build it fails with the following error...
Read more >
Java Generics Example Tutorial - Generic Method, Class ...
We use <T> to create a generic class, interface, and method. The T is replaced with the actual type when we use it....
Read more >
Generics: How They Work and Why They Are Important - Oracle
Conclusion. Generics enable the use of stronger type-checking, the elimination of casts, and the ability to develop generic algorithms. Without generics, many ...
Read more >
Generics in Java - GeeksforGeeks
Using Generics, it is possible to create classes that work with different data types. ... Generics in Java are similar to templates in...
Read more >
Constraints on type parameters - C# Programming Guide
Use type parameters as constraints on generic classes in scenarios in which you want to enforce an inheritance relationship between two type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found