Skip to content

Commit 5dc60f1

Browse files
dgp1130clydin
authored andcommitted
refactor(@angular-devkit/core): fix strict typing errors in node/
This fixes a few error surfaced by adding `"strict": true` to `tsconfig.json`. * `_callFs(fs.readdir, /* ... */)` needs explicit types because `fs.readdir` has a few overloads, which was confusing type inference. * `TempScopedNodeJsSyncHost._sync` is an uninitialized property, but it was already being checked for `undefined`, so I simply made its type optional. * `TempScopedNodeJsSyncHost.files` had an incorrect type assertion, but was otherwise correct. I just removed the assertion and let type inference do the trick.
1 parent ec0530b commit 5dc60f1

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

etc/api/angular_devkit/core/node/testing/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export declare class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost<fs.Stats> {
22
protected _root: Path;
3-
protected _sync: virtualFs.SyncDelegateHost<fs.Stats>;
3+
protected _sync?: virtualFs.SyncDelegateHost<fs.Stats>;
44
get files(): Path[];
55
get root(): Path;
66
get sync(): virtualFs.SyncDelegateHost<fs.Stats>;

packages/angular_devkit/core/node/host.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ export class NodeJsAsyncHost implements virtualFs.Host<fs.Stats> {
160160
}
161161

162162
list(path: Path): Observable<PathFragment[]> {
163-
return _callFs(fs.readdir, getSystemPath(path)).pipe(
164-
map((names: string[]) => names.map(name => fragment(name))),
163+
return _callFs<string[], string>(fs.readdir, getSystemPath(path)).pipe(
164+
map((names) => names.map(name => fragment(name))),
165165
);
166166
}
167167

packages/angular_devkit/core/node/testing/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { NodeJsSyncHost } from '../host';
1515
* A Sync Scoped Host that creates a temporary directory and scope to it.
1616
*/
1717
export class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost<fs.Stats> {
18-
protected _sync: virtualFs.SyncDelegateHost<fs.Stats>;
18+
protected _sync?: virtualFs.SyncDelegateHost<fs.Stats>;
1919
protected _root: Path;
2020

2121
constructor() {
@@ -30,8 +30,8 @@ export class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost<fs.Stats> {
3030
const sync = this.sync;
3131
function _visit(p: Path): Path[] {
3232
return sync.list(p)
33-
.map((fragment: PathFragment) => join(p, fragment))
34-
.reduce((files: Path[], path: PathFragment) => {
33+
.map((fragment) => join(p, fragment))
34+
.reduce((files, path) => {
3535
if (sync.isDirectory(path)) {
3636
return files.concat(_visit(path));
3737
} else {

0 commit comments

Comments
 (0)