Skip to content

Language Service doesn't support directive composition API #48102

Closed

Description

@wellwind

Which @angular/* package(s) are the source of the bug?

language-service

Is this a regression?

No

Description

Let say I have a directive like this:

import { Directive, HostBinding, Input } from '@angular/core';

@Directive({
  standalone: true,
  selector: '[appBgColor]'
})
export class BgColorDirective {
  @HostBinding('style.display') display = 'inline-block';
  @Input() @HostBinding('style.background-color') bgColor = 'yellow';
}

In the component, I want to use directive composition API including the inputs

import { Component } from '@angular/core';
import { BgColorDirective } from '../bg-color.directive';

@Component({
  selector: 'app-my-comp',
  templateUrl: './my-comp.component.html',
  styleUrls: ['./my-comp.component.scss'],
  hostDirectives: [
    {
      directive: BgColorDirective,
      inputs: ['bgColor']
    }
  ]
})
export class MyCompComponent { }

And the usage of component

<app-my-comp [bgColor]="'red'"></app-my-comp>

After compile, it works fine. But in VSCode, I got this error:

image

I think this is about the language service issue.

Please provide a link to a minimal reproduction of the bug

https://github.com/wellwind/ng-directive-composition-api-language-service-bug-demo

Please provide the exception or error you saw

It should has no error in VSCode.

Please provide the environment you discovered this bug in (run ng version)

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 15.0.0
Node: 16.17.0
Package Manager: npm 8.15.0
OS: darwin arm64

Angular: 15.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.0
@angular-devkit/build-angular   15.0.0
@angular-devkit/core            15.0.0
@angular-devkit/schematics      15.0.0
@schematics/angular             15.0.0
rxjs                            7.5.7
typescript                      4.8.4

Anything else?

No response

Activity

  1. self-assigned this
    on Nov 17, 2022
  2. atscott commented on Nov 17, 2022

    @atscott
    Contributor

    Are you using the latest version of the extension? The latest version of the extension is required because it bundles the Angular compiler and host directives were not supported pre-v15.

    Note: I downloaded your project everything appeared to be working.

  3. added
    needs: clarification
    area: language-service
    on Nov 17, 2022
  4. added this to the needsTriage milestone on Nov 17, 2022
  5. wellwind commented on Nov 17, 2022

    @wellwind
    ContributorAuthor

    I didn't notice the extension version, but it seems updated automatically, now I'm using v15.0.1 and all works fine. Thanks :)

  6. atscott commented on Nov 17, 2022

    @atscott
    Contributor

    @wellwind We did find some issues while investigating this. All inputs from the directive will be available in autocompletion (even if they're not listed in the hostDirective inputs). Also, host directives on other directives aren't showing up in completions (only for components)

  7. crisbeto commented on Nov 17, 2022

    @crisbeto
    Member

    I'll reopen this to investigate the issues Andrew mentioned.

  8. added and removed
    needs: clarification
    on Nov 21, 2022
  9. added a commit that references this issue on Nov 22, 2022
    cc8b76e
  10. angular-automatic-lock-bot commented on Dec 23, 2022

    @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.

  11. locked and limited conversation to collaborators on Dec 23, 2022
  12. added a commit that references this issue on Feb 1, 2023
    a21bbcb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: language-servicestate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions