Skip to content

Library compilation fails with compiler-cli v12.2.7 #43624

@amariq

Description

@amariq

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

compiler-cli

Is this a regression?

Yes

Description

Some changes in v12.2.7 of compiler-cli (type-checker fix from PR #43511, I believe), make my library compilation fail with the "Unable to write a reference to <SomeTypeName>" error.

The error occurs during compilation time and only if there is at least one usage of some component with type parameters, from another library, exists. Those type parameters are custom ones — not the built-in TS types, which seem to work fine.

Rolling back compiler-cli package to v12.2.6 makes compilation to work again.


Example:

  • my-lib1
export type MyValue<T, K extends keyof T = keyof T> = T | T[K];
export type MyValueArray<T> = T | T[];

@Component({
  selector: 'my-comp',
  template: `
    {{ value }}
  `,
})
export class MyComponent<T = any, V extends MyValue<T> = any> {
  @Input() data: T[];
  @Input() value: V;
}
  • my-lib2
@Component({
  selector: 'some-comp',
  template: `
    <my-comp [data]="[]" [value]="null"></my-comp>
  `,
})
export class SomeComponent {
   // empty
}

Then compilation of my-lib2 fails with the message:

Unable to write a reference to MyValue in my-lib1/.../my-component.d.ts from my-lib/.../some-component.ngtypecheck.ts.

Please provide a link to a minimal reproduction of the bug

https://github.com/amariq/angular-pr43511-bug

Please provide the exception or error you saw

✖ Compiling with Angular sources in Ivy partial compilation mode.
Unable to write a reference to <SomeInterface> in <some-lib>/.../<some-component>.d.ts from <my-lib>/.../<my-component>.ngtypecheck.ts

Please provide the environment you discovered this bug in

Angular CLI: 12.2.7
Node: 16.10.0
Package Manager: 7.24.1
OS: Windows 10 x64

Angular: 12.2.7
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy: "partial"


Package                                             Version
---------------------------------------------------------
@angular-devkit/build-angular                       12.2.7
@angular/animations                                 12.2.7
@angular/cli                                        12.2.7
@angular/common                                     12.2.7
@angular/compiler-cli                               12.2.7
@angular/compiler                                   12.2.7
@angular/core                                       12.2.7
@angular/forms                                      12.2.7
@angular/platform-browser-dynamic                   12.2.7
@angular/platform-browser                           12.2.7
@angular/router                                     12.2.7
ng-packagr                                          12.2.2
rxjs                                    	    6.6.7
tslib                                               2.3.1
typescript                                  	    4.3.5
zone.js                                 	    0.11.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilerstate: has PR

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions