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.
This commit is contained in:
Doug Parker 2020-08-11 17:29:04 -07:00 committed by Charles
parent ec0530b0d2
commit 5dc60f13c3
3 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
export declare class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost<fs.Stats> {
protected _root: Path;
protected _sync: virtualFs.SyncDelegateHost<fs.Stats>;
protected _sync?: virtualFs.SyncDelegateHost<fs.Stats>;
get files(): Path[];
get root(): Path;
get sync(): virtualFs.SyncDelegateHost<fs.Stats>;

View File

@ -160,8 +160,8 @@ export class NodeJsAsyncHost implements virtualFs.Host<fs.Stats> {
}
list(path: Path): Observable<PathFragment[]> {
return _callFs(fs.readdir, getSystemPath(path)).pipe(
map((names: string[]) => names.map(name => fragment(name))),
return _callFs<string[], string>(fs.readdir, getSystemPath(path)).pipe(
map((names) => names.map(name => fragment(name))),
);
}

View File

@ -15,7 +15,7 @@ import { NodeJsSyncHost } from '../host';
* A Sync Scoped Host that creates a temporary directory and scope to it.
*/
export class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost<fs.Stats> {
protected _sync: virtualFs.SyncDelegateHost<fs.Stats>;
protected _sync?: virtualFs.SyncDelegateHost<fs.Stats>;
protected _root: Path;
constructor() {
@ -30,8 +30,8 @@ export class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost<fs.Stats> {
const sync = this.sync;
function _visit(p: Path): Path[] {
return sync.list(p)
.map((fragment: PathFragment) => join(p, fragment))
.reduce((files: Path[], path: PathFragment) => {
.map((fragment) => join(p, fragment))
.reduce((files, path) => {
if (sync.isDirectory(path)) {
return files.concat(_visit(path));
} else {