@angular/core and @angular/compiler explicitly listed as dependencies in published package.json

Offen
#990 5 Kommentare 8 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
42/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
angular, typescript

Rechercherichtung

Untersuche die veröffentlichte package.json und angular/templates/basicTemplateAstVisitor.d.ts und reproduziere den TypeScript-Fehler mit den bereitgestellten Imports und Abhängigkeitsversionen. Prüfe, wie @angular/core und @angular/compiler deklariert und installiert sind, und verifiziere, dass das fertige Paket keine doppelten Angular-Typen mehr auflöst und die Reproduktion kompiliert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Describe the bug

I'm seeing a Typescript issue because of @angular/core being explicitly listed as a dependency of codelyzer.

Context and configuration

codelyzer lists @angular/core: 9.0.0 as an explicit dependency in its package.json, while my own app is running @angular/core: 9.2.13. I have a custom rule that extends BasicTemplateAstVisitor.

The following code snippet is a minimal reproduction of the scenario I'm facing:

import { ElementAst } from '@angular/compiler';
import { BasicTemplateAstVisitor } from 'codelyzer';

export class TemplateVisitorController extends BasicTemplateAstVisitor {
    visitElement(elementAst: ElementAst, context: BasicTemplateAstVisitor): void {
        this.validateElement(elementAst);
        super.visitElement(elementAst, context);
    }
}

This throws a Typescript error with the latest version of codelyzer:

libs/design-system-tslint/src/rules/util/designSystemComponentHelper.ts(51,5): error TS2416: Property 'visitElement' in type 'TemplateVisitorController' is not assignable to the same property in base type 'BasicTemplateAstVisitor'.
  Type '(elementAst: ElementAst, context: BasicTemplateAstVisitor) => any' is not assignable to type '(element: ElementAst, context: any) => any'.
    Types of parameters 'elementAst' and 'element' are incompatible.
      Type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").ElementAst' is not assignable to type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").ElementAst'.
        Types of property 'attrs' are incompatible.
          Type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst[]' is not assignable to type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst[]'.
            Type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst' is not assignable to type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst'.
              Types of property 'visit' are incompatible.
                Type '(visitor: import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor, context: any) => any' is not assignable to type '(visitor: import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor, context: any) => any'.
                  Types of parameters 'visitor' and 'visitor' are incompatible.
                    Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor'.
                      Types of property 'visitEmbeddedTemplate' are incompatible.
                        Type '(ast: import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst, context: any) => any' is not assignable to type '(ast: import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst, context: any) => any'.
                          Types of parameters 'ast' and 'ast' are incompatible.
                            Type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst' is not assignable to type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst'.
                              Types of property 'outputs' are incompatible.
                                Type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").BoundEventAst[]' is not assignable to type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").BoundEventAst[]'.
                                  Type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").BoundEventAst' is not assignable to type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").BoundEventAst'.
                                    Types of property 'handler' are incompatible.
                                      Type 'AST' is missing the following properties from type 'ASTWithSource': ast, source, location, errors
libs/design-system-tslint/src/rules/util/designSystemComponentHelper.ts(53,28): error TS2345: Argument of type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").ElementAst' is not assignable to parameter of type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").ElementAst'.
  Types of property 'attrs' are incompatible.
    Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst[]' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst[]'.
      Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").AttrAst'.
        Types of property 'visit' are incompatible.
          Type '(visitor: import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor, context: any) => any' is not assignable to type '(visitor: import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor, context: any) => any'.
            Types of parameters 'visitor' and 'visitor' are incompatible.
              Type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor' is not assignable to type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").TemplateAstVisitor'.
                Types of property 'visitEmbeddedTemplate' are incompatible.
                  Type '(ast: import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst, context: any) => any' is not assignable to type '(ast: import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst, context: any) => any'.
                    Types of parameters 'ast' and 'ast' are incompatible.
                      Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").EmbeddedTemplateAst'.
                        Types of property 'directives' are incompatible.
                          Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").DirectiveAst[]' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").DirectiveAst[]'.
                            Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").DirectiveAst' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").DirectiveAst'.
                              Types of property 'hostProperties' are incompatible.
                                Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").BoundElementPropertyAst[]' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").BoundElementPropertyAst[]'.
                                  Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").BoundElementPropertyAst' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").BoundElementPropertyAst'.
                                    Types of property 'type' are incompatible.
                                      Type 'import("/usr/src/app/node_modules/@angular/compiler/src/template_parser/template_ast").PropertyBindingType' is not assignable to type 'import("/usr/src/app/node_modules/codelyzer/node_modules/@angular/compiler/src/template_parser/template_ast").PropertyBindingType'.

This error stems from the fact that ElementAst in visitElement (node_modules\codelyzer\angular\templates\basicTemplateAstVisitor.d.ts) refers to node_modules\codelyzer\node_modules\@angular\compiler\src\template_parser\template_ast.d.ts as opposed to node_modules\@angular\compiler\compiler.d.ts.

Removing both @angular/core as well as @angular/compiler from the codelyzer package.json and running an npm i in node_modules/codelyzer addresses the issue locally, because it then starts using the right @angular/compiler.

So this makes me wonder: why are @angular/core and @angular/common explicitly listed as dependencies in the published package? AFAIK having dependencies in a package is bad idea, and peerDependencies are the way to go. Am I missing something here?

Expected behavior

No Typescript error should be thrown, since codelyzer should be using @angular/core from your main node_modules.

Proposed fix

Remove @angular/core and @angular/compiler from the published package.json.

Environment

Irrelevant AFAIK, can add if needed.

Vorherrschende Sprache
TypeScript
Sterne
2.5k
Forks
232
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus mgechev/codelyzer

Alle Issues in mgechev/codelyzer

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.