Skip to content

Commit 876ae1b

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 876ae1b

File tree

8 files changed

+34
-50
lines changed

8 files changed

+34
-50
lines changed

goldens/public-api/angular_devkit/core/index.api.md

+7-25
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ interface JsonVisitor {
389389

390390
// @public (undocumented)
391391
class LevelCapLogger extends LevelTransformLogger {
392-
constructor(name: string, parent: (Logger | null) | undefined, levelCap: LogLevel);
392+
constructor(name: string, parent: Logger | null, levelCap: LogLevel);
393393
// (undocumented)
394394
readonly levelCap: LogLevel;
395395
// (undocumented)
@@ -406,7 +406,7 @@ class LevelCapLogger extends LevelTransformLogger {
406406

407407
// @public (undocumented)
408408
class LevelTransformLogger extends Logger {
409-
constructor(name: string, parent: (Logger | null) | undefined, levelTransform: (level: LogLevel) => LogLevel);
409+
constructor(name: string, parent: Logger | null, levelTransform: (level: LogLevel) => LogLevel);
410410
// (undocumented)
411411
createChild(name: string): Logger;
412412
// (undocumented)
@@ -556,7 +556,7 @@ function parseJsonPointer(pointer: JsonPointer): string[];
556556
// @public (undocumented)
557557
export class PartiallyOrderedSet<T> implements Set<T> {
558558
// (undocumented)
559-
[Symbol.iterator](): Generator<T, undefined, unknown>;
559+
[Symbol.iterator](): IterableIterator<T, undefined, unknown>;
560560
// (undocumented)
561561
get [Symbol.toStringTag](): 'Set';
562562
// (undocumented)
@@ -941,29 +941,9 @@ class SimpleMemoryHost implements Host<{}> {
941941
// (undocumented)
942942
protected _list(path: Path): PathFragment[];
943943
// (undocumented)
944-
protected _newDirStats(): {
945-
inspect(): string;
946-
isFile(): boolean;
947-
isDirectory(): boolean;
948-
size: number;
949-
atime: Date;
950-
ctime: Date;
951-
mtime: Date;
952-
birthtime: Date;
953-
content: null;
954-
};
944+
protected _newDirStats(): Stats<SimpleMemoryHostStats>;
955945
// (undocumented)
956-
protected _newFileStats(content: FileBuffer, oldStats?: Stats<SimpleMemoryHostStats>): {
957-
inspect(): string;
958-
isFile(): boolean;
959-
isDirectory(): boolean;
960-
size: number;
961-
atime: Date;
962-
ctime: Date;
963-
mtime: Date;
964-
birthtime: Date;
965-
content: ArrayBuffer;
966-
};
946+
protected _newFileStats(content: FileBuffer, oldStats?: Stats<SimpleMemoryHostStats>): Stats<SimpleMemoryHostStats>;
967947
// (undocumented)
968948
read(path: Path): Observable<FileBuffer>;
969949
// (undocumented)
@@ -995,6 +975,8 @@ class SimpleMemoryHost implements Host<{}> {
995975
interface SimpleMemoryHostStats {
996976
// (undocumented)
997977
readonly content: FileBuffer | null;
978+
// (undocumented)
979+
inspect(): string;
998980
}
999981

1000982
// @public (undocumented)

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)