angularsignalsangular2-directives

Angular 17.1 Signal Inputs on directive?


I'm able to use the new Angular's 17.1 Signal Inputs as follows:

{
    public value: InputSignal<string> = input.required<string>();
}

And while it works on components, it does not on my directives. It however seems to be supported according to this post:

@directive({..})
export class MyDir {
  firstName = input<string>();            // string|undefined
  lastName = input.required<string>();    // string
  age = input(0);                         // number

For instance, here is my directive:

@Directive({
    selector: '[appMyDirective]',
    standalone: true,
    exportAs: 'myDirective',
})
export class MyDirective {
    public value: InputSignal<string> = input.required<string>();
}

The compiler will complain:

  <app-my-component
    appMyDirective
    [value]="aValue"
  </app-my-component>

I get an error like this:

Error: example.component.html:14:6 - error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'Signal<string>'.
  Property '["@angular/core".ɵINPUT_SIGNAL_BRAND_WRITE_TYPE]' does not exist on type 'Signal<string>'.

14     [value]="aValue"

Since the Signal input feature was released last week, it might be a bug, but I'm open to suggestions if I'm doing something wrong.


Solution

  • After removing the cache and rebuilding the app, the compilation error is gone but I'm still having a warning on webstorm : enter image description here

    As (warningapart), the code works as expected, I have now to understand why webstorm is complaining, but this is another issue.

    [EDIT]: Upgrading webstorm fixed the issue...