Skip to content

Commit dbbe8c9

Browse files
committed
refactor(@angular-devkit/core): additional isolated declarations cleanup
To eventually support the use of the TypeScript `isolatedDeclarations` option, additional type adjustments have been made to code within the `@angular-devkit/core` package. While this is not yet comprehensive, it significantly reduces the amount of build errors with the `isolatedDeclarations` option enabled.
1 parent 9f50436 commit dbbe8c9

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

packages/angular_devkit/core/src/logger/level.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { LogLevel, Logger } from './logger';
1212
export class LevelTransformLogger extends Logger {
1313
constructor(
1414
public override readonly name: string,
15-
public override readonly parent: Logger | null = null,
15+
public override readonly parent: Logger | null,
1616
public readonly levelTransform: (level: LogLevel) => LogLevel,
1717
) {
1818
super(name, parent);
@@ -38,7 +38,7 @@ export class LevelCapLogger extends LevelTransformLogger {
3838

3939
constructor(
4040
public override readonly name: string,
41-
public override readonly parent: Logger | null = null,
41+
public override readonly parent: Logger | null,
4242
public readonly levelCap: LogLevel,
4343
) {
4444
super(name, parent, (level: LogLevel) => {

packages/angular_devkit/core/src/utils/partially-ordered-set.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ export class CircularDependencyFoundException extends BaseException {
2222
export class PartiallyOrderedSet<T> implements Set<T> {
2323
private _items = new Map<T, Set<T>>();
2424

25-
protected _checkCircularDependencies(item: T, deps: Set<T>) {
25+
protected _checkCircularDependencies(item: T, deps: Set<T>): void {
2626
if (deps.has(item)) {
2727
throw new CircularDependencyFoundException();
2828
}
2929

3030
deps.forEach((dep) => this._checkCircularDependencies(item, this._items.get(dep) || new Set()));
3131
}
3232

33-
clear() {
33+
clear(): void {
3434
this._items.clear();
3535
}
36-
has(item: T) {
36+
has(item: T): boolean {
3737
return this._items.has(item);
3838
}
39-
get size() {
39+
get size(): number {
4040
return this._items.size;
4141
}
4242
forEach(
@@ -71,7 +71,7 @@ export class PartiallyOrderedSet<T> implements Set<T> {
7171
return this[Symbol.iterator]();
7272
}
7373

74-
add(item: T, deps: Set<T> | T[] = new Set()) {
74+
add(item: T, deps: Set<T> | T[] = new Set()): this {
7575
if (Array.isArray(deps)) {
7676
deps = new Set(deps);
7777
}
@@ -119,7 +119,7 @@ export class PartiallyOrderedSet<T> implements Set<T> {
119119
return this;
120120
}
121121

122-
delete(item: T) {
122+
delete(item: T): boolean {
123123
if (!this._items.has(item)) {
124124
return false;
125125
}
@@ -130,7 +130,7 @@ export class PartiallyOrderedSet<T> implements Set<T> {
130130
return this._items.delete(item);
131131
}
132132

133-
*[Symbol.iterator]() {
133+
*[Symbol.iterator](): IterableIterator<T, undefined, unknown> {
134134
const copy: Map<T, Set<T>> = new Map(this._items);
135135

136136
for (const [key, value] of copy.entries()) {

packages/angular_devkit/core/src/virtual-fs/host/memory.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ import {
3636

3737
export interface SimpleMemoryHostStats {
3838
readonly content: FileBuffer | null;
39+
inspect(): string;
3940
}
4041

4142
export class SimpleMemoryHost implements Host<{}> {
42-
protected _cache = new Map<Path, Stats<SimpleMemoryHostStats>>();
43+
protected _cache: Map<Path, Stats<SimpleMemoryHostStats>> = new Map();
4344
private _watchers = new Map<Path, [HostWatchOptions, Subject<HostWatchEvent>][]>();
4445

45-
protected _newDirStats() {
46+
protected _newDirStats(): Stats<SimpleMemoryHostStats> {
4647
return {
47-
inspect() {
48+
inspect(): string {
4849
return '<Directory>';
4950
},
5051

@@ -64,7 +65,10 @@ export class SimpleMemoryHost implements Host<{}> {
6465
content: null,
6566
};
6667
}
67-
protected _newFileStats(content: FileBuffer, oldStats?: Stats<SimpleMemoryHostStats>) {
68+
protected _newFileStats(
69+
content: FileBuffer,
70+
oldStats?: Stats<SimpleMemoryHostStats>,
71+
): Stats<SimpleMemoryHostStats> {
6872
return {
6973
inspect() {
7074
return `<File size(${content.byteLength})>`;

packages/angular_devkit/core/src/virtual-fs/host/pattern.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type ReplacementFunction = (path: Path) => Path;
1515
/**
1616
*/
1717
export class PatternMatchingHost<StatsT extends object = {}> extends ResolverHost<StatsT> {
18-
protected _patterns = new Map<RegExp, ReplacementFunction>();
18+
protected _patterns: Map<RegExp, ReplacementFunction> = new Map();
1919

2020
addPattern(pattern: string | string[], replacementFn: ReplacementFunction): void {
2121
const patterns = Array.isArray(pattern) ? pattern : [pattern];

packages/angular_devkit/core/src/virtual-fs/host/record.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ export type CordHostRecord = CordHostCreate | CordHostOverwrite | CordHostRename
6868
* the create/overwrite records IIF the files does/doesn't already exist.
6969
*/
7070
export class CordHost extends SimpleMemoryHost {
71-
protected _filesToCreate = new Set<Path>();
72-
protected _filesToRename = new Map<Path, Path>();
73-
protected _filesToRenameRevert = new Map<Path, Path>();
74-
protected _filesToDelete = new Set<Path>();
75-
protected _filesToOverwrite = new Set<Path>();
71+
protected _filesToCreate: Set<Path> = new Set();
72+
protected _filesToRename: Map<Path, Path> = new Map();
73+
protected _filesToRenameRevert: Map<Path, Path> = new Map();
74+
protected _filesToDelete: Set<Path> = new Set();
75+
protected _filesToOverwrite: Set<Path> = new Set();
7676

7777
constructor(protected _back: ReadonlyHost) {
7878
super();

packages/angular_devkit/core/src/virtual-fs/path.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ export type PathFragment = Path & {
4141

4242
/**
4343
* The Separator for normalized path.
44-
* @type {Path}
4544
*/
46-
export const NormalizedSep = '/' as Path;
45+
export const NormalizedSep: Path = '/' as Path;
4746

4847
/**
4948
* The root of a normalized path.
50-
* @type {Path}
5149
*/
52-
export const NormalizedRoot = NormalizedSep;
50+
export const NormalizedRoot: Path = NormalizedSep;
5351

5452
/**
5553
* Split a path into multiple path fragments. Each fragments except the last one will end with
@@ -192,7 +190,7 @@ let normalizedCache = new Map<string, Path>();
192190
* Reset the cache. This is only useful for testing.
193191
* @private
194192
*/
195-
export function resetNormalizeCache() {
193+
export function resetNormalizeCache(): void {
196194
normalizedCache = new Map<string, Path>();
197195
}
198196

packages/angular_devkit/core/src/workspace/json/metadata.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function escapeKey(key: string): string | number {
3535
}
3636

3737
export class JsonWorkspaceMetadata {
38-
readonly changes = new Map<string, JsonChange>();
38+
readonly changes: Map<string, JsonChange> = new Map();
3939

4040
hasLegacyTargetsName = true;
4141

0 commit comments

Comments
 (0)