diff --git a/packages/localize/schematics/ng-add/index_spec.ts b/packages/localize/schematics/ng-add/index_spec.ts index fabd645919..11457db983 100644 --- a/packages/localize/schematics/ng-add/index_spec.ts +++ b/packages/localize/schematics/ng-add/index_spec.ts @@ -177,9 +177,10 @@ export { renderModule, renderModuleFactory } from '@angular/platform-server';`; it('should add package to `devDependencies` by default', async () => { host = await schematicRunner.runSchematicAsync('ng-add', defaultOptions, host).toPromise(); const packageJsonText = host.readContent('/package.json'); - expect(JSON.parse(packageJsonText).devDependencies?.['@angular/localize']) - .toBe('~0.0.0-PLACEHOLDER'); - expect(JSON.parse(packageJsonText).dependencies?.['@angular/localize']).toBeUndefined(); + const packageJsonObj = JSON.parse(packageJsonText) as + {devDependencies: {[key: string]: string}, dependencies: {[key: string]: string}}; + expect(packageJsonObj.devDependencies?.['@angular/localize']).toBe('~0.0.0-PLACEHOLDER'); + expect(packageJsonObj.dependencies?.['@angular/localize']).toBeUndefined(); }); it('should add package to `dependencies` if `useAtRuntime` is `true`', async () => { @@ -187,8 +188,9 @@ export { renderModule, renderModuleFactory } from '@angular/platform-server';`; .runSchematicAsync('ng-add', {...defaultOptions, useAtRuntime: true}, host) .toPromise(); const packageJsonText = host.readContent('/package.json'); - expect(JSON.parse(packageJsonText).dependencies?.['@angular/localize']) - .toBe('~0.0.0-PLACEHOLDER'); - expect(JSON.parse(packageJsonText).devDependencies?.['@angular/localize']).toBeUndefined(); + const packageJsonObj = JSON.parse(packageJsonText) as + {devDependencies: {[key: string]: string}, dependencies: {[key: string]: string}}; + expect(packageJsonObj.dependencies?.['@angular/localize']).toBe('~0.0.0-PLACEHOLDER'); + expect(packageJsonObj.devDependencies?.['@angular/localize']).toBeUndefined(); }); }); diff --git a/packages/localize/src/tools/src/extract/translation_files/format_options.ts b/packages/localize/src/tools/src/extract/translation_files/format_options.ts index 43113678bb..4ef8bb98e6 100644 --- a/packages/localize/src/tools/src/extract/translation_files/format_options.ts +++ b/packages/localize/src/tools/src/extract/translation_files/format_options.ts @@ -40,5 +40,5 @@ export function validateOptions(name: string, validOptions: ValidOptions, option * @param optionString The string to parse. */ export function parseFormatOptions(optionString: string = '{}'): FormatOptions { - return JSON.parse(optionString); -} \ No newline at end of file + return JSON.parse(optionString) as FormatOptions; +} diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.ts index 990b16a74b..db4b52b400 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/arb_translation_parser.ts @@ -93,7 +93,7 @@ export class ArbTranslationParser implements TranslationParser { } private tryParseArbFormat(contents: string): ArbJsonObject { - const json = JSON.parse(contents); + const json = JSON.parse(contents) as ArbJsonObject; if (typeof json['@@locale'] !== 'string') { throw new Error('Missing @@locale property.'); } diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.ts index 6f695c4c9d..f104a53bbf 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/simple_json_translation_parser.ts @@ -11,6 +11,11 @@ import {Diagnostics} from '../../../diagnostics'; import {ParseAnalysis, ParsedTranslationBundle, TranslationParser} from './translation_parser'; +interface SimpleJsonFile { + locale: string; + translations: {[messageId: string]: string}; +} + /** * A translation parser that can parse JSON that has the form: * @@ -27,16 +32,16 @@ import {ParseAnalysis, ParsedTranslationBundle, TranslationParser} from './trans * @see SimpleJsonTranslationSerializer * @publicApi used by CLI */ -export class SimpleJsonTranslationParser implements TranslationParser { +export class SimpleJsonTranslationParser implements TranslationParser { /** * @deprecated */ - canParse(filePath: string, contents: string): Object|false { + canParse(filePath: string, contents: string): SimpleJsonFile|false { const result = this.analyze(filePath, contents); return result.canParse && result.hint; } - analyze(filePath: string, contents: string): ParseAnalysis { + analyze(filePath: string, contents: string): ParseAnalysis { const diagnostics = new Diagnostics(); // For this to be parsable, the extension must be `.json` and the contents must include "locale" // and "translations" keys. @@ -46,7 +51,7 @@ export class SimpleJsonTranslationParser implements TranslationParser { return {canParse: false, diagnostics}; } try { - const json = JSON.parse(contents); + const json = JSON.parse(contents) as SimpleJsonFile; if (json.locale === undefined) { diagnostics.warn('Required "locale" property missing.'); return {canParse: false, diagnostics}; @@ -70,8 +75,8 @@ export class SimpleJsonTranslationParser implements TranslationParser { } } - parse(_filePath: string, contents: string, json?: Object): ParsedTranslationBundle { - const {locale: parsedLocale, translations} = json || JSON.parse(contents); + parse(_filePath: string, contents: string, json?: SimpleJsonFile): ParsedTranslationBundle { + const {locale: parsedLocale, translations} = json || JSON.parse(contents) as SimpleJsonFile; const parsedTranslations: Record<ɵMessageId, ɵParsedTranslation> = {}; for (const messageId in translations) { const targetMessage = translations[messageId];