Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(schematics): fix for angular 12 and align schematics #437

Conversation

DaSchTour
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[X] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #434

What is the new behavior?

Added the type property and also improved the behavior for angular 12 which validates the input and breaks on unkown options

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

Sadly I couldn't test it locally because the build broke because of some rxjs issues in ActivatedRouteStub

* @param raw initial object
* @param keys list of keys to remove from object
*/
function _omit<T extends Record<string, any>>(raw: T, keys: (keyof T)[]): any {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I think this function is doing the opposite of what you want it to!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benelliott is right. Check your filter logic.

@@ -23,6 +23,7 @@
"angular testing dumb components"
],
"dependencies": {
"@angular-devkit/core": ">= 10.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenn I tried to run this as a linked package it complained that @angular-devkit/core was not found although it was installed in the project.

@@ -21,7 +21,7 @@ import { ComponentOptions, DirectiveOptions, ServiceOptions } from './schema';
export function spectatorComponentSchematic(options: ComponentOptions): Rule {
return chain([
externalSchematic('@schematics/angular', 'component', {
...options,
..._omit(options, ['jest', 'withHost', 'withCustomHost']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain, please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Angular 12 complains about options that are passed but not known

* @param raw initial object
* @param keys list of keys to remove from object
*/
function _omit<T extends Record<string, any>>(raw: T, keys: (keyof T)[]): any {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benelliott is right. Check your filter logic.

@NetanelBasal
Copy link
Member

Thanks for the PR. See my comments, and please check that it works.

@DaSchTour DaSchTour force-pushed the bugfix/angular-12-schematic-alignment branch from cf640dd to 584bdfd Compare May 21, 2021 07:06
@DaSchTour
Copy link
Author

I fixed the filter logic, but I'm not able to test because build is broken.

Building Angular Package

------------------------------------------------------------------------------
Building entry point '@ngneat/spectator'
------------------------------------------------------------------------------
✖ Compiling TypeScript sources through NGC
ERROR: projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:44:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

44     this.params = this.paramsSubject.asObservable();
       ~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:45:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>'.

45     this.queryParams = this.queryParamsSubject.asObservable();
       ~~~~~~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:46:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Data>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Data>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

46     this.data = this.dataSubject.asObservable();
       ~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:47:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<string>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<string>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

47     this.fragment = this.fragmentSubject.asObservable() as Observable<string>;
       ~~~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:48:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").UrlSegment[]>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").UrlSegment[]>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

48     this.url = this.urlSubject.asObservable() as Observable<UrlSegment[]>;
       ~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:55:14 - error TS2416: Property 'paramMap' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>'.
    The types of 'source.operator.call' are incompatible between these types.
      Type '(subscriber: import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>, source: any) => import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/types").TeardownLogic' is not assignable to type '(subscriber: import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>, source: any) => import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/types").TeardownLogic'.
        Types of parameters 'subscriber' and 'subscriber' are incompatible.
[31[39mm          Type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>'.
            Property 'isStopped' is protected but type 'Subscriber<T>' is not a class derived from 'Subscriber<T>'.

55   public get paramMap(): Observable<ParamMap> {
                ~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:101:14 - error TS2416: Property 'root' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.
    Types of property 'paramMap' are incompatible.
      Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>'.

101   public get root(): ActivatedRouteStub {
                 ~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:105:14 - error TS2416: Property 'parent' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub | null' is not assignable to type 'ActivatedRoute | null'.
    Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.

105   public get parent(): ActivatedRouteStub | null {
                 ~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:109:14 - error TS2416: Property 'children' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub[]' is not assignable to type 'ActivatedRoute[]'.
    Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.

109   public get children(): ActivatedRouteStub[] {
                 ~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:113:14 - error TS2416: Property 'firstChild' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub | null' is not assignable to type 'ActivatedRoute | null'.
    Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.

113   public get firstChild(): ActivatedRouteStub | null {
                 ~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/create-factory.ts:105:5 - error TS2352: Conversion of type 'ActivatedRoute' to type 'SpyObject<ActivatedRouteStub>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'ActivatedRoute' is missing the following properties from type 'ActivatedRouteStub': testParams, testQueryParams, testData, testFragment, and 20 more.

105     TestBed.inject(ActivatedRoute) as SpyObject<ActivatedRouteStub>
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/create-factory.ts:105:5 - error TS2352: Conversion of type 'ActivatedRoute' to type 'SpyObject<ActivatedRouteStub>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'ActivatedRoute' is not comparable to type 'ActivatedRouteStub'.

105     TestBed.inject(ActivatedRoute) as SpyObject<ActivatedRouteStub>
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

An unhandled exception occurred: projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:44:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

44     this.params = this.paramsSubject.asObservable();
       ~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:45:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Params>'.

45     this.queryParams = this.queryParamsSubject.asObservable();
       ~~~~~~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:46:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Data>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").Data>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

46     this.data = this.dataSubject.asObservable();
       ~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:47:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<string>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<string>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

47     this.fragment = this.fragmentSubject.asObservable() as Observable<string>;
       ~~~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:48:5 - error TS2322: Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").UrlSegment[]>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").UrlSegment[]>'.
  Types of property 'source' are incompatible.
    Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<any>'.

48     this.url = this.urlSubject.asObservable() as Observable<UrlSegment[]>;
       ~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:55:14 - error TS2416: Property 'paramMap' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>'.
    The types of 'source.operator.call' are incompatible between these types.
      Type '(subscriber: import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>, source: any) => import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/types").TeardownLogic' is not assignable to type '(subscriber: import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>, source: any) => import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/types").TeardownLogic'.
        Types of parameters 'subscriber' and 'subscriber' are incompatible.
          Type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Subscriber").Subscriber<any>'.
            Property 'isStopped' is protected but type 'Subscriber<T>' is not a class derived from 'Subscriber<T>'.

55   public get paramMap(): Observable<ParamMap> {
                ~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:101:14 - error TS2416: Property 'root' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.
    Types of property 'paramMap' are incompatible.
      Type 'import("/Users/dasch/Projekte/spectator/projects/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>' is not assignable to type 'import("/Users/dasch/Projekte/spectator/node_modules/rxjs/internal/Observable").Observable<import("/Users/dasch/Projekte/spectator/node_modules/@angular/router/router").ParamMap>'.

101   public get root(): ActivatedRouteStub {
                 ~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:105:14 - error TS2416: Property 'parent' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub | null' is not assignable to type 'ActivatedRoute | null'.
    Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.

105   public get parent(): ActivatedRouteStub | null {
                 ~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:109:14 - error TS2416: Property 'children' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub[]' is not assignable to type 'ActivatedRoute[]'.
    Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.

109   public get children(): ActivatedRouteStub[] {
                 ~~~~~~~~
projects/spectator/src/lib/spectator-routing/activated-route-stub.ts:113:14 - error TS2416: Property 'firstChild' in type 'ActivatedRouteStub' is not assignable to the same property in base type 'ActivatedRoute'.
  Type 'ActivatedRouteStub | null' is not assignable to type 'ActivatedRoute | null'.
    Type 'ActivatedRouteStub' is not assignable to type 'ActivatedRoute'.

113   public get firstChild(): ActivatedRouteStub | null {
                 ~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/create-factory.ts:105:5 - error TS2352: Conversion of type 'ActivatedRoute' to type 'SpyObject<ActivatedRouteStub>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'ActivatedRoute' is missing the following properties from type 'ActivatedRouteStub': testParams, testQueryParams, testData, testFragment, and 20 more.

105     TestBed.inject(ActivatedRoute) as SpyObject<ActivatedRouteStub>
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
projects/spectator/src/lib/spectator-routing/create-factory.ts:105:5 - error TS2352: Conversion of type 'ActivatedRoute' to type 'SpyObject<ActivatedRouteStub>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Type 'ActivatedRoute' is not comparable to type 'ActivatedRouteStub'.

105     TestBed.inject(ActivatedRoute) as SpyObject<ActivatedRouteStub>
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@DaSchTour DaSchTour mentioned this pull request Jun 10, 2021
@DaSchTour DaSchTour force-pushed the bugfix/angular-12-schematic-alignment branch from 584bdfd to 3d1b088 Compare July 7, 2021 05:39
@cmplank
Copy link

cmplank commented Jul 15, 2021

@DaSchTour Can you clarify about the build being broken? Are you waiting on another issue to be resolved or just stuck on this fix because your changes broke the build and you don't know how to fix it?

@DaSchTour
Copy link
Author

@cmplank I actually have now idea what this build issue is about. For me it looks completely unrelated. But I have no idea how to fix it and why it breaks.

I just checked, the same issue is there on master. So it's not related to my changes.

@NetanelBasal
Copy link
Member

There is a PR

@DaSchTour
Copy link
Author

Yeah, I see. Thanks.
Closing this in favor of #457

@DaSchTour DaSchTour closed this Jul 16, 2021
@DaSchTour DaSchTour deleted the bugfix/angular-12-schematic-alignment branch July 21, 2021 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants