Skip to content

Commit 21e8783

Browse files
committed
Make JSON.parse return unknown instead of any
The type of object is returns is really unknown.
1 parent b534fb4 commit 21e8783

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

lib/lib.es5.d.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*! *****************************************************************************
2-
Copyright (c) Microsoft Corporation. All rights reserved.
2+
Copyright (c) Microsoft Corporation. All rights reserved.
33
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
44
this file except in compliance with the License. You may obtain a copy of the
5-
License at http://www.apache.org/licenses/LICENSE-2.0
6-
5+
License at http://www.apache.org/licenses/LICENSE-2.0
6+
77
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
88
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10-
MERCHANTABLITY OR NON-INFRINGEMENT.
11-
9+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10+
MERCHANTABLITY OR NON-INFRINGEMENT.
11+
1212
See the Apache Version 2.0 License for specific language governing permissions
1313
and limitations under the License.
1414
***************************************************************************** */
@@ -597,7 +597,7 @@ interface TemplateStringsArray extends ReadonlyArray<string> {
597597

598598
/**
599599
* The type of `import.meta`.
600-
*
600+
*
601601
* If you need to declare that a given property exists on `import.meta`,
602602
* this type may be augmented via interface merging.
603603
*/
@@ -1039,14 +1039,19 @@ interface URIErrorConstructor {
10391039

10401040
declare const URIError: URIErrorConstructor;
10411041

1042+
type JSONPrimitive = string | number | boolean | null;
1043+
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
1044+
type JSONObject = { [member: string]: JSONValue };
1045+
interface JSONArray extends Array<JSONValue> {}
1046+
10421047
interface JSON {
10431048
/**
10441049
* Converts a JavaScript Object Notation (JSON) string into an object.
10451050
* @param text A valid JSON string.
10461051
* @param reviver A function that transforms the results. This function is called for each member of the object.
10471052
* If a member contains nested objects, the nested objects are transformed before the parent object is.
10481053
*/
1049-
parse(text: string, reviver?: (key: any, value: any) => any): any;
1054+
parse(text: string, reviver?: (key: any, value: any) => any): JSONValue;
10501055
/**
10511056
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
10521057
* @param value A JavaScript value, usually an object or array, to be converted.

scripts/configurePrerelease.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function main(): void {
2828

2929
// Acquire the version from the package.json file and modify it appropriately.
3030
const packageJsonFilePath = normalize(args[1]);
31-
const packageJsonValue: PackageJson = JSON.parse(readFileSync(packageJsonFilePath).toString());
31+
const packageJsonValue = JSON.parse(readFileSync(packageJsonFilePath).toString()) as PackageJson;
3232

3333
const { majorMinor, patch } = parsePackageJsonVersion(packageJsonValue.version);
3434
const prereleasePatch = getPrereleasePatch(tag, patch);

scripts/generateLocalizedDiagnosticMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function main(): void {
136136
writeFile(
137137
path.join(outputPath, "enu", "diagnosticMessages.generated.json.lcg"),
138138
getLCGFileXML(
139-
objectToList(JSON.parse(data.toString()))
139+
objectToList(JSON.parse(data.toString()) as Record<string, string>)
140140
.sort((a, b) => a.key > b.key ? 1 : -1) // lcg sorted by property keys
141141
.reduce((s, { key, value }) => s + getItemXML(key, value), "")
142142
));

scripts/processDiagnosticMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function main(): void {
2727
console.log(`Reading diagnostics from ${inputFilePath}`);
2828
const inputStr = fs.readFileSync(inputFilePath, { encoding: "utf-8" });
2929

30-
const diagnosticMessagesJson: { [key: string]: DiagnosticDetails } = JSON.parse(inputStr);
30+
const diagnosticMessagesJson = JSON.parse(inputStr) as { [key: string]: DiagnosticDetails };
3131

3232
const diagnosticMessages: InputDiagnosticMessageTable = new Map();
3333
for (const key in diagnosticMessagesJson) {

0 commit comments

Comments
 (0)