fix(bazel): update type castings for JSON.parse usage (#40710)

Update usages of JSON.parse to be cast as specific types.

PR Close #40710
This commit is contained in:
Joey Perrott
2021-02-04 14:40:21 -08:00
committed by Alex Rickabaugh
parent e721a5d258
commit 2c90391d4b
4 changed files with 24 additions and 11 deletions
+3 -3
View File
@@ -91,7 +91,7 @@ function main(args: string[]): number {
const typeDefinitions = typeDefinitionsArg.split(',').filter(s => !!s);
const srcs = srcsArg.split(',').filter(s => !!s);
const dataFiles: string[] = dataArg.split(',').filter(s => !!s);
const modulesManifest = JSON.parse(modulesManifestArg);
const modulesManifest = JSON.parse(modulesManifestArg) as Record<string, any>;
const dtsBundles: string[] = dtsBundleArg.split(',').filter(s => !!s);
/**
@@ -226,7 +226,7 @@ function main(args: string[]): number {
let content = fs.readFileSync(src, 'utf-8');
// Modify package.json files as necessary for publishing
if (path.basename(src) === 'package.json') {
const packageJson = JSON.parse(content);
const packageJson = JSON.parse(content) as {[key: string]: string};
content = amendPackageJson(src, packageJson, false);
const packageName = packageJson['name'];
@@ -439,7 +439,7 @@ export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, '')
* @param typingsPath the typings bundle entrypoint
*/
function rewireMetadata(metadataPath: string, typingsPath: string): string {
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf-8')) as {[key: string]: any};
let typingsRelativePath =
normalizeSeparators(path.relative(path.dirname(metadataPath), typingsPath));
+3 -2
View File
@@ -377,8 +377,9 @@ export function compile({
if (importedFilePath.indexOf('node_modules') >= 0) {
const maybeMetadataFile = importedFilePath.replace(EXT, '') + '.metadata.json';
if (fs.existsSync(maybeMetadataFile)) {
const moduleName =
JSON.parse(fs.readFileSync(maybeMetadataFile, {encoding: 'utf-8'})).importAs;
const moduleName = (JSON.parse(fs.readFileSync(maybeMetadataFile, {encoding: 'utf-8'})) as {
importAs: string
}).importAs;
if (moduleName) {
return moduleName;
}