Skip to content

Commit 2027d1b

Browse files
committed
refactor(@angular-devkit/schematics): add explicit return types to functions
To support the eventual use of the TypeScript `isolatedDeclarations` option, explicit return types have been added to functions throughout the `@angular-devkit/schematics` package code.
1 parent c79a246 commit 2027d1b

File tree

10 files changed

+41
-37
lines changed

10 files changed

+41
-37
lines changed

packages/angular_devkit/schematics/src/engine/engine.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ export class CollectionImpl<CollectionT extends object, SchematicT extends objec
9090
public readonly baseDescriptions?: Array<CollectionDescription<CollectionT>>,
9191
) {}
9292

93-
get description() {
93+
get description(): CollectionDescription<CollectionT> {
9494
return this._description;
9595
}
96-
get name() {
96+
get name(): string {
9797
return this.description.name || '<unknown>';
9898
}
9999

@@ -183,10 +183,10 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
183183
protected _workflow?: Workflow,
184184
) {}
185185

186-
get workflow() {
186+
get workflow(): Workflow | null {
187187
return this._workflow || null;
188188
}
189-
get defaultMergeStrategy() {
189+
get defaultMergeStrategy(): MergeStrategy {
190190
return this._host.defaultMergeStrategy || MergeStrategy.Default;
191191
}
192192

packages/angular_devkit/schematics/src/engine/schematic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export class SchematicImpl<CollectionT extends object, SchematicT extends object
4141
}
4242
}
4343

44-
get description() {
44+
get description(): SchematicDescription<CollectionT, SchematicT> {
4545
return this._description;
4646
}
47-
get collection() {
47+
get collection(): Collection<CollectionT, SchematicT> {
4848
return this._collection;
4949
}
5050

packages/angular_devkit/schematics/src/sink/host.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class HostSink extends SimpleSinkBase {
8686
return EMPTY;
8787
}
8888

89-
_done() {
89+
_done(): Observable<void> {
9090
// Really commit everything to the actual filesystem.
9191
return concatObservables(
9292
observableFrom([...this._filesToDelete.values()]).pipe(

packages/angular_devkit/schematics/src/tree/action.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@ let _id = 1;
2727
export class ActionList implements Iterable<Action> {
2828
private _actions: Action[] = [];
2929

30-
protected _action(action: Partial<Action>) {
30+
protected _action(action: Partial<Action>): void {
3131
this._actions.push({
3232
...(action as Action),
3333
id: _id++,
3434
parent: this._actions[this._actions.length - 1]?.id ?? 0,
3535
});
3636
}
3737

38-
create(path: Path, content: Buffer) {
38+
create(path: Path, content: Buffer): void {
3939
this._action({ kind: 'c', path, content });
4040
}
41-
overwrite(path: Path, content: Buffer) {
41+
overwrite(path: Path, content: Buffer): void {
4242
this._action({ kind: 'o', path, content });
4343
}
44-
rename(path: Path, to: Path) {
44+
rename(path: Path, to: Path): void {
4545
this._action({ kind: 'r', path, to });
4646
}
47-
delete(path: Path) {
47+
delete(path: Path): void {
4848
this._action({ kind: 'd', path });
4949
}
5050

51-
optimize() {
51+
optimize(): void {
5252
const toCreate = new Map<Path, Buffer>();
5353
const toRename = new Map<Path, Path>();
5454
const toOverwrite = new Map<Path, Buffer>();
@@ -122,13 +122,13 @@ export class ActionList implements Iterable<Action> {
122122
});
123123
}
124124

125-
push(action: Action) {
125+
push(action: Action): void {
126126
this._actions.push(action);
127127
}
128-
get(i: number) {
128+
get(i: number): Action {
129129
return this._actions[i];
130130
}
131-
has(action: Action) {
131+
has(action: Action): boolean {
132132
for (let i = 0; i < this._actions.length; i++) {
133133
const a = this._actions[i];
134134
if (a.id == action.id) {
@@ -144,10 +144,10 @@ export class ActionList implements Iterable<Action> {
144144
find(predicate: (value: Action) => boolean): Action | null {
145145
return this._actions.find(predicate) || null;
146146
}
147-
forEach(fn: (value: Action, index: number, array: Action[]) => void, thisArg?: {}) {
147+
forEach(fn: (value: Action, index: number, array: Action[]) => void, thisArg?: {}): void {
148148
this._actions.forEach(fn, thisArg);
149149
}
150-
get length() {
150+
get length(): number {
151151
return this._actions.length;
152152
}
153153
[Symbol.iterator](): IterableIterator<Action> {

packages/angular_devkit/schematics/src/tree/entry.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export class SimpleFileEntry implements FileEntry {
1515
private _content: Buffer,
1616
) {}
1717

18-
get path() {
18+
get path(): Path {
1919
return this._path;
2020
}
21-
get content() {
21+
get content(): Buffer {
2222
return this._content;
2323
}
2424
}
@@ -31,10 +31,10 @@ export class LazyFileEntry implements FileEntry {
3131
private _load: (path?: Path) => Buffer,
3232
) {}
3333

34-
get path() {
34+
get path(): Path {
3535
return this._path;
3636
}
37-
get content() {
37+
get content(): Buffer {
3838
return this._content || (this._content = this._load(this._path));
3939
}
4040
}

packages/angular_devkit/schematics/src/tree/host-tree.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class HostTree implements Tree {
107107

108108
private _dirCache = new Map<Path, HostDirEntry>();
109109

110-
[TreeSymbol]() {
110+
[TreeSymbol](): this {
111111
return this;
112112
}
113113

@@ -132,19 +132,19 @@ export class HostTree implements Tree {
132132
return normalize('/' + path);
133133
}
134134

135-
protected _willCreate(path: Path) {
135+
protected _willCreate(path: Path): boolean {
136136
return this._record.willCreate(path);
137137
}
138138

139-
protected _willOverwrite(path: Path) {
139+
protected _willOverwrite(path: Path): boolean {
140140
return this._record.willOverwrite(path);
141141
}
142142

143-
protected _willDelete(path: Path) {
143+
protected _willDelete(path: Path): boolean {
144144
return this._record.willDelete(path);
145145
}
146146

147-
protected _willRename(path: Path) {
147+
protected _willRename(path: Path): boolean {
148148
return this._record.willRename(path);
149149
}
150150

packages/angular_devkit/schematics/src/tree/null.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ export class NullTreeDirEntry implements DirEntry {
4343
return null;
4444
}
4545

46-
visit() {}
46+
visit(): void {}
4747
}
4848

4949
export class NullTree implements Tree {
50-
[TreeSymbol]() {
50+
[TreeSymbol](): this {
5151
return this;
5252
}
5353

@@ -74,10 +74,10 @@ export class NullTree implements Tree {
7474
get(_path: string) {
7575
return null;
7676
}
77-
getDir(path: string) {
77+
getDir(path: string): NullTreeDirEntry {
7878
return new NullTreeDirEntry(normalize('/' + path));
7979
}
80-
visit() {}
80+
visit(): void {}
8181

8282
// Change content of host files.
8383
beginUpdate(path: string): never {

packages/angular_devkit/schematics/src/tree/recorder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ export class UpdateRecorderBase implements UpdateRecorder {
5959
return new UpdateRecorderBase(entry.content, entry.path);
6060
}
6161

62-
get path() {
62+
get path(): string {
6363
return this._path;
6464
}
6565

66-
protected _assertIndex(index: number) {
66+
protected _assertIndex(index: number): void {
6767
if (index < 0 || index > this.content.original.length) {
6868
throw new IndexOutOfBoundException(index, 0, this.content.original.length);
6969
}

packages/angular_devkit/schematics/src/tree/scoped.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class ScopedTree implements Tree {
197197
return scopedActions;
198198
}
199199

200-
[TreeSymbol]() {
200+
[TreeSymbol](): this {
201201
return this;
202202
}
203203

packages/angular_devkit/schematics/src/tree/static.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ import { SchematicsException } from '../exception/exception';
1010
import { FilterHostTree, HostTree } from './host-tree';
1111
import { FilePredicate, MergeStrategy, Tree } from './interface';
1212

13-
export function empty() {
13+
export function empty(): HostTree {
1414
return new HostTree();
1515
}
1616

17-
export function branch(tree: Tree) {
17+
export function branch(tree: Tree): Tree {
1818
return tree.branch();
1919
}
2020

21-
export function merge(tree: Tree, other: Tree, strategy: MergeStrategy = MergeStrategy.Default) {
21+
export function merge(
22+
tree: Tree,
23+
other: Tree,
24+
strategy: MergeStrategy = MergeStrategy.Default,
25+
): Tree {
2226
tree.merge(other, strategy);
2327

2428
return tree;

0 commit comments

Comments
 (0)