Giter Club home page Giter Club logo

Comments (2)

JoostK avatar JoostK commented on April 27, 2024 1

If you change new FormGroup(...) to new FormGroup<T>(...) you'll get

Argument of type '{ codipostalMercaderies_input: FormControl<string>; katr10_input: FormControl<boolean>; nomMercaderies_input: FormControl<string>; poblacioMercaderies_input: FormControl<...>; ... 20 more ...; pais_input: FormControl<...>; }' is not assignable to parameter of type 'T'.
  'T' could be instantiated with an arbitrary type which could be unrelated to '{ codipostalMercaderies_input: FormControl<string>; katr10_input: FormControl<boolean>; nomMercaderies_input: FormControl<string>; poblacioMercaderies_input: FormControl<...>; ... 20 more ...; pais_input: FormControl<...>; }'.

which exposes a real problem with this code, unrelated to the typings of @angular/forms: T may require additional properties that are not present in the FormGroup's controls object.

The error message isn't great here due to @angular/forms's complexity to support typed forms in a backwards compatible way, but it's fundamentally an issue with your code.

from angular.

alxhub avatar alxhub commented on April 27, 2024 1

As @JoostK explains, he type error is a bit hard to parse here, but is correct.

parent declares a generic type T with the bound of extends iZmerControls. This type could be iZmerControls, or it could be some type which extends iZmerControls and adds extra controls. For example:

interface MyControls extends iZmerControls {
  someName: FormControl<number>;
}

new parent<MyControls>();

What TypeScript is telling you is that new FormGroup({...}) in parent can't be proven to satisfy T, since it might be missing controls which are present in the extended T. For example, it would be missing someName in the case of new parent<MyControls> above.

from angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.