Skip to content

Commit c30fc63

Browse files
devversionzarend
authored andcommitted
refactor: privately expose types needed for mixins to avoid broken type definitions
Since we updated the TypeScript module and target to ES2020/ESNext for both devmode and prodmode output, tbe type definition files will no longer get the AMD naming patches from `@bazel/typescript`. These previously ensured that with `module: "umd"`, TypeScript never can generate relatie imports, but rather uses AMD module names. The removal of this logic now breaks the type definition output because there is code in `@angular/material-experimental` which imports from Angular Material core in a way where TypeScript would try to write an inferred type into the `d.ts` out. This results in a deep import right now because some of the symbols used for the inferred type are not publicly exposed. This commit exposes them privately so that TS can avoid deep imports. The goldens have been updated accordingly. The deep imports can be observed there as well.
1 parent 364acff commit c30fc63

30 files changed

+93
-72
lines changed

scripts/check-mdc-exports.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,11 @@ function getExports(name: string): string[] {
8686
const typeChecker = program.getTypeChecker();
8787
const mainSymbol = typeChecker.getSymbolAtLocation(sourceFile);
8888

89-
return (mainSymbol ? (typeChecker.getExportsOfModule(mainSymbol) || []) : []).map(symbol => {
90-
// tslint:disable-next-line:no-bitwise
91-
if (symbol.flags & ts.SymbolFlags.Alias) {
92-
const resolvedSymbol = typeChecker.getAliasedSymbol(symbol);
93-
return (!resolvedSymbol.valueDeclaration && !resolvedSymbol.declarations) ?
94-
symbol : resolvedSymbol;
95-
} else {
96-
return symbol;
97-
}
98-
}).map(symbol => symbol.name);
89+
if (mainSymbol === undefined) {
90+
return [];
91+
}
92+
93+
return typeChecker.getExportsOfModule(mainSymbol).map(symbol => symbol.name);
9994
}
10095

10196
/** Checks whether a particular Material package has an MDC-based equivalent. */

src/material-experimental/mdc-core/public-api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ export {
5656
setLines,
5757
ShowOnDirtyErrorStateMatcher,
5858
ThemePalette,
59-
VERSION
59+
VERSION,
60+
// Note: These need to be exposed privately for cross-package type inference. e.g. if the
61+
// experimental package uses a mixin, TS will try to write an explicit type reference that
62+
// is equivalent to e.g. `CanColorCtor`. For this it needs these two helpers as otherwise it
63+
// would generate a deep cross-package import that breaks in the NPM package output.
64+
_AbstractConstructor,
65+
_Constructor,
6066
} from '@angular/material/core';

src/material/core/common-behaviors/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ export {
1212
SanityChecks,
1313
GranularSanityChecks,
1414
} from './common-module';
15+
16+
// Note: These need to be exposed privately for cross-package type inference. e.g. if the
17+
// experimental package uses a mixin, TS will try to write an explicit type reference that
18+
// is equivalent to e.g. `CanColorCtor`. For this it needs these two helpers as otherwise it
19+
// would generate a deep cross-package import that breaks in the NPM package output.
20+
export {
21+
Constructor as _Constructor,
22+
AbstractConstructor as _AbstractConstructor
23+
} from './constructor';
24+
1525
export {CanDisable, mixinDisabled} from './disabled';
1626
export {CanColor, mixinColor, ThemePalette} from './color';
1727
export {CanDisableRipple, mixinDisableRipple} from './disable-ripple';

tools/public_api_guard/material/autocomplete.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
55
```ts
66

7-
import { AbstractConstructor } from '@angular/material/core/common-behaviors/constructor';
7+
import { _AbstractConstructor } from '@angular/material/core';
88
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y';
99
import { AfterContentInit } from '@angular/core';
1010
import { AfterViewInit } from '@angular/core';
1111
import { BooleanInput } from '@angular/cdk/coercion';
1212
import { CanDisableRipple } from '@angular/material/core';
1313
import { ChangeDetectorRef } from '@angular/core';
14-
import { Constructor } from '@angular/material/core/common-behaviors/constructor';
14+
import { _Constructor } from '@angular/material/core';
1515
import { ControlValueAccessor } from '@angular/forms';
1616
import { Directionality } from '@angular/cdk/bidi';
1717
import { ElementRef } from '@angular/core';

tools/public_api_guard/material/badge.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
55
```ts
66

7-
import { AbstractConstructor } from '@angular/material/core/common-behaviors/constructor';
7+
import { _AbstractConstructor } from '@angular/material/core';
88
import { AriaDescriber } from '@angular/cdk/a11y';
99
import { BooleanInput } from '@angular/cdk/coercion';
1010
import { CanDisable } from '@angular/material/core';
11-
import { Constructor } from '@angular/material/core/common-behaviors/constructor';
11+
import { _Constructor } from '@angular/material/core';
1212
import { ElementRef } from '@angular/core';
1313
import * as i0 from '@angular/core';
1414
import * as i2 from '@angular/cdk/a11y';

tools/public_api_guard/material/button-toggle.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
55
```ts
66

7-
import { AbstractConstructor } from '@angular/material/core/common-behaviors/constructor';
7+
import { _AbstractConstructor } from '@angular/material/core';
88
import { AfterContentInit } from '@angular/core';
99
import { AfterViewInit } from '@angular/core';
1010
import { BooleanInput } from '@angular/cdk/coercion';
1111
import { CanDisableRipple } from '@angular/material/core';
1212
import { ChangeDetectorRef } from '@angular/core';
13-
import { Constructor } from '@angular/material/core/common-behaviors/constructor';
13+
import { _Constructor } from '@angular/material/core';
1414
import { ControlValueAccessor } from '@angular/forms';
1515
import { ElementRef } from '@angular/core';
1616
import { EventEmitter } from '@angular/core';

tools/public_api_guard/material/button.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
55
```ts
66

7-
import { AbstractConstructor } from '@angular/material/core/common-behaviors/constructor';
7+
import { _AbstractConstructor } from '@angular/material/core';
88
import { AfterViewInit } from '@angular/core';
99
import { BooleanInput } from '@angular/cdk/coercion';
1010
import { CanColor } from '@angular/material/core';
1111
import { CanDisable } from '@angular/material/core';
1212
import { CanDisableRipple } from '@angular/material/core';
13-
import { Constructor } from '@angular/material/core/common-behaviors/constructor';
13+
import { _Constructor } from '@angular/material/core';
1414
import { ElementRef } from '@angular/core';
1515
import { FocusableOption } from '@angular/cdk/a11y';
1616
import { FocusMonitor } from '@angular/cdk/a11y';

tools/public_api_guard/material/checkbox.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```ts
66

7-
import { AbstractConstructor } from '@angular/material/core/common-behaviors/constructor';
7+
import { _AbstractConstructor } from '@angular/material/core';
88
import { AfterViewChecked } from '@angular/core';
99
import { AfterViewInit } from '@angular/core';
1010
import { BooleanInput } from '@angular/cdk/coercion';
@@ -13,7 +13,7 @@ import { CanDisable } from '@angular/material/core';
1313
import { CanDisableRipple } from '@angular/material/core';
1414
import { ChangeDetectorRef } from '@angular/core';
1515
import { CheckboxRequiredValidator } from '@angular/forms';
16-
import { Constructor } from '@angular/material/core/common-behaviors/constructor';
16+
import { _Constructor } from '@angular/material/core';
1717
import { ControlValueAccessor } from '@angular/forms';
1818
import { ElementRef } from '@angular/core';
1919
import { EventEmitter } from '@angular/core';

tools/public_api_guard/material/chips.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
55
```ts
66

7-
import { AbstractConstructor } from '@angular/material/core/common-behaviors/constructor';
7+
import { _AbstractConstructor } from '@angular/material/core';
88
import { AfterContentInit } from '@angular/core';
99
import { BooleanInput } from '@angular/cdk/coercion';
1010
import { CanColor } from '@angular/material/core';
1111
import { CanDisable } from '@angular/material/core';
1212
import { CanDisableRipple } from '@angular/material/core';
1313
import { CanUpdateErrorState } from '@angular/material/core';
1414
import { ChangeDetectorRef } from '@angular/core';
15-
import { Constructor } from '@angular/material/core/common-behaviors/constructor';
15+
import { _Constructor } from '@angular/material/core';
1616
import { ControlValueAccessor } from '@angular/forms';
1717
import { Directionality } from '@angular/cdk/bidi';
1818
import { DoCheck } from '@angular/core';

tools/public_api_guard/material/core.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
55
```ts
66

7-
import { AbstractConstructor as AbstractConstructor_2 } from '@angular/material/core/common-behaviors/constructor';
7+
import { _AbstractConstructor as _AbstractConstructor_2 } from '@angular/material/core';
88
import { AfterViewChecked } from '@angular/core';
99
import { BooleanInput } from '@angular/cdk/coercion';
1010
import { ChangeDetectorRef } from '@angular/core';
11-
import { Constructor as Constructor_2 } from '@angular/material/core/common-behaviors/constructor';
11+
import { _Constructor as _Constructor_2 } from '@angular/material/core';
1212
import { ElementRef } from '@angular/core';
1313
import { EventEmitter } from '@angular/core';
1414
import { FocusableOption } from '@angular/cdk/a11y';
@@ -33,6 +33,9 @@ import { QueryList } from '@angular/core';
3333
import { Subject } from 'rxjs';
3434
import { Version } from '@angular/core';
3535

36+
// @public
37+
export type _AbstractConstructor<T = object> = abstract new (...args: any[]) => T;
38+
3639
// @public
3740
export class AnimationCurves {
3841
// (undocumented)
@@ -79,6 +82,9 @@ export interface CanUpdateErrorState {
7982
updateErrorState(): void;
8083
}
8184

85+
// @public
86+
export type _Constructor<T> = new (...args: any[]) => T;
87+
8288
// @public
8389
export function _countGroupLabelsBeforeOption(optionIndex: number, options: QueryList<MatOption>, optionGroups: QueryList<MatOptgroup>): number;
8490

@@ -404,22 +410,22 @@ export class MatRippleModule {
404410
}
405411

406412
// @public
407-
export function mixinColor<T extends AbstractConstructor<HasElementRef>>(base: T, defaultColor?: ThemePalette): CanColorCtor & T;
413+
export function mixinColor<T extends _AbstractConstructor<HasElementRef>>(base: T, defaultColor?: ThemePalette): CanColorCtor & T;
408414

409415
// @public
410-
export function mixinDisabled<T extends AbstractConstructor<{}>>(base: T): CanDisableCtor & T;
416+
export function mixinDisabled<T extends _AbstractConstructor<{}>>(base: T): CanDisableCtor & T;
411417

412418
// @public
413-
export function mixinDisableRipple<T extends AbstractConstructor<{}>>(base: T): CanDisableRippleCtor & T;
419+
export function mixinDisableRipple<T extends _AbstractConstructor<{}>>(base: T): CanDisableRippleCtor & T;
414420

415421
// @public
416-
export function mixinErrorState<T extends AbstractConstructor<HasErrorState>>(base: T): CanUpdateErrorStateCtor & T;
422+
export function mixinErrorState<T extends _AbstractConstructor<HasErrorState>>(base: T): CanUpdateErrorStateCtor & T;
417423

418424
// @public
419-
export function mixinInitialized<T extends Constructor<{}>>(base: T): HasInitializedCtor & T;
425+
export function mixinInitialized<T extends _Constructor<{}>>(base: T): HasInitializedCtor & T;
420426

421427
// @public
422-
export function mixinTabIndex<T extends AbstractConstructor<CanDisable>>(base: T, defaultTabIndex?: number): HasTabIndexCtor & T;
428+
export function mixinTabIndex<T extends _AbstractConstructor<CanDisable>>(base: T, defaultTabIndex?: number): HasTabIndexCtor & T;
423429

424430
// @public
425431
export class NativeDateAdapter extends DateAdapter<Date> {

0 commit comments

Comments
 (0)