Skip to content

Commit 0efa119

Browse files
kyliaupull[bot]
authored andcommitted
fix(@angular-devkit/core): strict typings for json, logger, and virtual-fs
This commit fixes typings errors after "strict: true" is enabled in tsconfig.json for the json, logger, and virtual-fs subpackages in `@angular-devkit/core`.
1 parent 550097a commit 0efa119

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

etc/api/angular_devkit/core/src/_golden-api.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export interface CordHostRename {
214214

215215
export declare class CoreSchemaRegistry implements SchemaRegistry {
216216
constructor(formats?: SchemaFormat[]);
217-
protected _resolver(ref: string, validate: ajv.ValidateFunction): {
217+
protected _resolver(ref: string, validate?: ajv.ValidateFunction): {
218218
context?: ajv.ValidateFunction;
219219
schema?: JsonObject;
220220
};
@@ -1147,7 +1147,7 @@ export declare namespace test {
11471147
};
11481148
class TestHost extends SimpleMemoryHost {
11491149
protected _records: TestLogRecord[];
1150-
protected _sync: SyncDelegateHost<{}>;
1150+
protected _sync: SyncDelegateHost<{}> | null;
11511151
get files(): Path[];
11521152
get records(): TestLogRecord[];
11531153
get sync(): SyncDelegateHost<{}>;

packages/angular_devkit/core/src/json/schema/registry.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class SchemaValidationException extends BaseException {
5858
) {
5959
if (!errors || errors.length === 0) {
6060
super('Schema validation failed.');
61+
this.errors = [];
6162

6263
return;
6364
}
@@ -194,7 +195,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
194195

195196
protected _resolver(
196197
ref: string,
197-
validate: ajv.ValidateFunction,
198+
validate?: ajv.ValidateFunction,
198199
): { context?: ajv.ValidateFunction, schema?: JsonObject } {
199200
if (!validate || !validate.refs || !validate.refVal || !ref) {
200201
return {};
@@ -396,10 +397,10 @@ export class CoreSchemaRegistry implements SchemaRegistry {
396397
switchMap(updatedData => {
397398
const result = validate.call(validationContext, updatedData);
398399

399-
return typeof result == 'boolean'
400+
return typeof result === 'boolean'
400401
? of([updatedData, result])
401402
: from((result as Promise<boolean>)
402-
.then(r => [updatedData, true])
403+
.then(() => [updatedData, true])
403404
.catch((err: Error | AjvValidationError) => {
404405
if ((err as AjvValidationError).ajv) {
405406
validate.errors = (err as AjvValidationError).errors;
@@ -410,7 +411,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
410411
return Promise.reject(err);
411412
}));
412413
}),
413-
switchMap(([data, valid]: [JsonValue, boolean]) => {
414+
switchMap(([data, valid]) => {
414415
if (valid) {
415416
let result = of(data);
416417

@@ -430,7 +431,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
430431
return of([data, valid]);
431432
}
432433
}),
433-
map(([data, valid]: [JsonValue, boolean]) => {
434+
map(([data, valid]) => {
434435
if (valid) {
435436
return { data, success: true } as SchemaValidatorResult;
436437
}
@@ -519,7 +520,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
519520
this._ajv.addKeyword('x-prompt', {
520521
errors: false,
521522
valid: true,
522-
compile: (schema, parentSchema: JsonObject, it) => {
523+
compile: (schema, parentSchema, it) => {
523524
const compilationSchemInfo = this._currentCompilationSchemaInfo;
524525
if (!compilationSchemInfo) {
525526
return () => true;
@@ -540,17 +541,17 @@ export class CoreSchemaRegistry implements SchemaRegistry {
540541
items = schema.items;
541542
}
542543

543-
const propertyTypes = getTypesOfSchema(parentSchema);
544+
const propertyTypes = getTypesOfSchema(parentSchema as JsonObject);
544545
if (!type) {
545546
if (propertyTypes.size === 1 && propertyTypes.has('boolean')) {
546547
type = 'confirmation';
547-
} else if (Array.isArray(parentSchema.enum)) {
548+
} else if (Array.isArray((parentSchema as JsonObject).enum)) {
548549
type = 'list';
549550
} else if (
550551
propertyTypes.size === 1 &&
551552
propertyTypes.has('array') &&
552-
parentSchema.items &&
553-
Array.isArray((parentSchema.items as JsonObject).enum)
553+
(parentSchema as JsonObject).items &&
554+
Array.isArray(((parentSchema as JsonObject).items as JsonObject).enum)
554555
) {
555556
type = 'list';
556557
} else {
@@ -566,8 +567,8 @@ export class CoreSchemaRegistry implements SchemaRegistry {
566567
: schema.multiselect;
567568

568569
const enumValues = multiselect
569-
? parentSchema.items && (parentSchema.items as JsonObject).enum
570-
: parentSchema.enum;
570+
? (parentSchema as JsonObject).items && ((parentSchema as JsonObject).items as JsonObject).enum
571+
: (parentSchema as JsonObject).enum;
571572
if (!items && Array.isArray(enumValues)) {
572573
items = [];
573574
for (const value of enumValues) {
@@ -590,11 +591,11 @@ export class CoreSchemaRegistry implements SchemaRegistry {
590591
items,
591592
multiselect,
592593
default:
593-
typeof parentSchema.default == 'object' &&
594-
parentSchema.default !== null &&
595-
!Array.isArray(parentSchema.default)
594+
typeof (parentSchema as JsonObject).default == 'object' &&
595+
(parentSchema as JsonObject).default !== null &&
596+
!Array.isArray((parentSchema as JsonObject).default)
596597
? undefined
597-
: parentSchema.default as string[],
598+
: (parentSchema as JsonObject).default as string[],
598599
async validator(data: JsonValue) {
599600
try {
600601
return await it.self.validate(parentSchema, data);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Observable, Operator, PartialObserver, Subject, Subscription } from 'rxjs';
8+
import { Observable, Operator, PartialObserver, Subject, Subscription, empty } from 'rxjs';
99
import { JsonObject } from '../json/interface';
1010

1111

@@ -35,8 +35,8 @@ export class Logger extends Observable<LogEntry> implements LoggerApi {
3535
protected readonly _subject: Subject<LogEntry> = new Subject<LogEntry>();
3636
protected _metadata: LoggerMetadata;
3737

38-
private _obs: Observable<LogEntry>;
39-
private _subscription: Subscription | null;
38+
private _obs: Observable<LogEntry> = empty();
39+
private _subscription: Subscription | null = null;
4040

4141
protected get _observable() { return this._obs; }
4242
protected set _observable(v: Observable<LogEntry>) {
@@ -142,7 +142,7 @@ export class Logger extends Observable<LogEntry> implements LoggerApi {
142142
subscribe(_observerOrNext?: PartialObserver<LogEntry> | ((value: LogEntry) => void),
143143
_error?: (error: Error) => void,
144144
_complete?: () => void): Subscription {
145-
return this._observable.subscribe.apply(this._observable, arguments);
145+
return this._observable.subscribe.apply(this._observable, arguments as unknown);
146146
}
147147
forEach(next: (value: LogEntry) => void, PromiseCtor?: typeof Promise): Promise<void> {
148148
return this._observable.forEach(next, PromiseCtor);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function fileBufferToString(fileBuffer: FileBuffer): string {
7373
if (i + chunkLength > bufLength) {
7474
chunkLength = bufLength - i;
7575
}
76-
result += String.fromCharCode.apply(null, bufView.subarray(i, i + chunkLength));
76+
result += String.fromCharCode.apply(null, [...bufView.subarray(i, i + chunkLength)]);
7777
}
7878

7979
return result;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export namespace test {
2727

2828
export class TestHost extends SimpleMemoryHost {
2929
protected _records: TestLogRecord[] = [];
30-
protected _sync: SyncDelegateHost<{}>;
30+
protected _sync: SyncDelegateHost<{}>|null = null;
3131

3232
constructor(map: { [path: string]: string } = {}) {
3333
super();

0 commit comments

Comments
 (0)