Skip to content

Type checking signal call in templates #49657

Closed

Description

@edbzn

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Let's say I omit to call a signal in the template, as we are used to with regular values.

@Component({
  template: `{{ value }}`,
})
export class AppComponent {
  value = signal('Hello World!')
}

No compilation error to prevent this error, resulting in an undesired string rendered to the screen: function () { [native code] }.

Proposed solution

Strict type-checking of signal calls in the template would improve DX, especially for newcomers.

Alternatives considered

No type checking.

Activity

  1. eneajaho commented on Mar 31, 2023

    @eneajaho
    Contributor

    Hi,
    This would be more appropriate as a template diagnostic rather than typecheck error.

    What about cases like:

    <app-test [value]="value" />
    export class TestCmp {
      @Input() value!: SettableSignal;
    }

    Should this throw an error? Probably not.

    So, this would make sense only in interpolation imo.

  2. JeanMeche commented on Mar 31, 2023

    @JeanMeche
    Member

    I drafted a PR for this. If the team is ready to include this diagnostic, I can finish working on it 👍

  3. eneajaho commented on Mar 31, 2023

    @eneajaho
    Contributor

    I was thinking what about this:

    {{ mySignal | myPipeThatAcceptsSignal }}

    How that would behave?

  4. JeanMeche commented on Mar 31, 2023

    @JeanMeche
    Member

    I was thinking what about this:

    {{ mySignal | myPipeThatAcceptsSignal }}
    

    How that would behave?

    That's already handled by the typing. For example with a Signal<number> and un Pipe.transform(number) you'll get :

    Argument of type 'WritableSignal<number>' is not assignable to parameter of type 'number'.

  5. added
    area: core
    on Apr 4, 2023
  6. added this to the needsTriage milestone on Apr 4, 2023
  7. added
    area: compiler
    and removed
    area: core
    on Apr 4, 2023
  8. pkozlowski-opensource commented on Oct 11, 2023

    @pkozlowski-opensource
    Member

    With #49660 merged I think that we are in a much better state. Going to close it for now, will see if people bump into other common cases.

  9. angular-automatic-lock-bot commented on Nov 11, 2023

    @angular-automatic-lock-bot

    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.

  10. locked and limited conversation to collaborators on Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions