diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index bbfcb7b93e98e..ab4f5b1334746 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -1056,7 +1056,7 @@ interface JSON { * @param reviver A function that transforms the results. This function is called for each member of the object. * If a member contains nested objects, the nested objects are transformed before the parent object is. */ - parse(text: string, reviver?: (this: any, key: string, value: any) => any): any; + parse(text: string, reviver?: (this: any, key: string, value: any) => any): T; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8fec41fba5fce..f70a9bd51df64 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -620,7 +620,7 @@ namespace ts { /*@internal*/ export function getBuildInfo(buildInfoText: string) { - return JSON.parse(buildInfoText) as BuildInfo; + return JSON.parse(buildInfoText); } /*@internal*/ diff --git a/src/harness/documentsUtil.ts b/src/harness/documentsUtil.ts index c07142e794fb7..da68a7983546c 100644 --- a/src/harness/documentsUtil.ts +++ b/src/harness/documentsUtil.ts @@ -78,7 +78,7 @@ namespace documents { private _sourceLineMappings: Mapping[][][] = []; constructor(mapFile: string | undefined, data: string | RawSourceMap) { - this.raw = typeof data === "string" ? JSON.parse(data) as RawSourceMap : data; + this.raw = typeof data === "string" ? JSON.parse(data) : data; this.mapFile = mapFile; this.version = this.raw.version; this.file = this.raw.file; @@ -184,4 +184,4 @@ namespace documents { return vlq; } } -} \ No newline at end of file +} diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index e111d36d117ad..8da5fda9f6734 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1036,7 +1036,7 @@ interface JSON { * @param reviver A function that transforms the results. This function is called for each member of the object. * If a member contains nested objects, the nested objects are transformed before the parent object is. */ - parse(text: string, reviver?: (this: any, key: string, value: any) => any): any; + parse(text: string, reviver?: (this: any, key: string, value: any) => any): T; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. diff --git a/src/server/session.ts b/src/server/session.ts index d02b8dd0e85dc..9486b91cca408 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -2756,7 +2756,7 @@ namespace ts.server { let request: protocol.Request | undefined; let relevantFile: protocol.FileRequestArgs | undefined; try { - request = JSON.parse(message); + request = JSON.parse(message); relevantFile = request.arguments && (request as protocol.FileRequest).arguments.file ? (request as protocol.FileRequest).arguments : undefined; perfLogger.logStartCommand("" + request.command, message.substring(0, 100)); diff --git a/src/services/shims.ts b/src/services/shims.ts index c8149620b8c6e..15e4c01190e8a 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -346,7 +346,7 @@ namespace ts { // 'in' does not have this effect. if ("getModuleResolutionsForFile" in this.shimHost) { this.resolveModuleNames = (moduleNames, containingFile) => { - const resolutionsInFile = >JSON.parse(this.shimHost.getModuleResolutionsForFile!(containingFile)); // TODO: GH#18217 + const resolutionsInFile = JSON.parse>(this.shimHost.getModuleResolutionsForFile!(containingFile)); // TODO: GH#18217 return map(moduleNames, name => { const result = getProperty(resolutionsInFile, name); return result ? { resolvedFileName: result, extension: extensionFromPath(result), isExternalLibraryImport: false } : undefined; @@ -358,7 +358,7 @@ namespace ts { } if ("getTypeReferenceDirectiveResolutionsForFile" in this.shimHost) { this.resolveTypeReferenceDirectives = (typeDirectiveNames, containingFile) => { - const typeDirectivesForFile = >JSON.parse(this.shimHost.getTypeReferenceDirectiveResolutionsForFile!(containingFile)); // TODO: GH#18217 + const typeDirectivesForFile = JSON.parse>(this.shimHost.getTypeReferenceDirectiveResolutionsForFile!(containingFile)); // TODO: GH#18217 return map(typeDirectiveNames, name => getProperty(typeDirectivesForFile, name)); }; } @@ -406,7 +406,7 @@ namespace ts { if (settingsJson === null || settingsJson === "") { throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings"); } - const compilerOptions = JSON.parse(settingsJson); + const compilerOptions = JSON.parse(settingsJson); // permit language service to handle all files (filtering should be performed on the host side) compilerOptions.allowNonTsExtensions = true; return compilerOptions; @@ -948,7 +948,7 @@ namespace ts { return this.forwardJSONCall( `getCompletionEntryDetails('${fileName}', ${position}, '${entryName}')`, () => { - const localOptions: FormatCodeOptions = formatOptions === undefined ? undefined : JSON.parse(formatOptions); + const localOptions: FormatCodeOptions | undefined = formatOptions === undefined ? undefined : JSON.parse(formatOptions); return this.languageService.getCompletionEntryDetails(fileName, position, entryName, localOptions, source, preferences); } ); @@ -1116,7 +1116,7 @@ namespace ts { public resolveModuleName(fileName: string, moduleName: string, compilerOptionsJson: string): string { return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => { - const compilerOptions = JSON.parse(compilerOptionsJson); + const compilerOptions = JSON.parse(compilerOptionsJson); const result = resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host); let resolvedFileName = result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined; if (result.resolvedModule && result.resolvedModule.extension !== Extension.Ts && result.resolvedModule.extension !== Extension.Tsx && result.resolvedModule.extension !== Extension.Dts) { @@ -1132,7 +1132,7 @@ namespace ts { public resolveTypeReferenceDirective(fileName: string, typeReferenceDirective: string, compilerOptionsJson: string): string { return this.forwardJSONCall(`resolveTypeReferenceDirective(${fileName})`, () => { - const compilerOptions = JSON.parse(compilerOptionsJson); + const compilerOptions = JSON.parse(compilerOptionsJson); const result = resolveTypeReferenceDirective(typeReferenceDirective, normalizeSlashes(fileName), compilerOptions, this.host); return { resolvedFileName: result.resolvedTypeReferenceDirective ? result.resolvedTypeReferenceDirective.resolvedFileName : undefined, @@ -1163,7 +1163,7 @@ namespace ts { return this.forwardJSONCall( `getAutomaticTypeDirectiveNames('${compilerOptionsJson}')`, () => { - const compilerOptions = JSON.parse(compilerOptionsJson); + const compilerOptions = JSON.parse(compilerOptionsJson); return getAutomaticTypeDirectiveNames(compilerOptions, this.host); } ); @@ -1212,7 +1212,7 @@ namespace ts { public discoverTypings(discoverTypingsJson: string): string { const getCanonicalFileName = createGetCanonicalFileName(/*useCaseSensitivefileNames:*/ false); return this.forwardJSONCall("discoverTypings()", () => { - const info = JSON.parse(discoverTypingsJson); + const info = JSON.parse(discoverTypingsJson); if (this.safeList === undefined) { this.safeList = JsTyping.loadSafeList(this.host, toPath(info.safeListPath, info.safeListPath, getCanonicalFileName)); } diff --git a/src/testRunner/projectsRunner.ts b/src/testRunner/projectsRunner.ts index d90972fe09a76..8f3dfe900d9a1 100644 --- a/src/testRunner/projectsRunner.ts +++ b/src/testRunner/projectsRunner.ts @@ -183,7 +183,7 @@ namespace project { } try { - testCase = JSON.parse(testFileText!); + testCase = JSON.parse(testFileText!); } catch (e) { throw assert(false, "Testcase: " + testCaseFileName + " does not contain valid json format: " + e.message); diff --git a/src/testRunner/runner.ts b/src/testRunner/runner.ts index c3d7d72c2a9d1..0767cb9e79665 100644 --- a/src/testRunner/runner.ts +++ b/src/testRunner/runner.ts @@ -94,7 +94,7 @@ namespace Harness { export let globalTimeout: number; function handleTestConfig() { if (testConfigContent !== "") { - const testConfig = JSON.parse(testConfigContent); + const testConfig = JSON.parse(testConfigContent); if (testConfig.light) { setLightMode(true); } @@ -262,4 +262,4 @@ namespace Harness { } startTestEnvironment(); -} \ No newline at end of file +} diff --git a/src/typingsInstaller/nodeTypingsInstaller.ts b/src/typingsInstaller/nodeTypingsInstaller.ts index c2ac253dd0137..09873ca112373 100644 --- a/src/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/typingsInstaller/nodeTypingsInstaller.ts @@ -54,7 +54,7 @@ namespace ts.server.typingsInstaller { return createMap>(); } try { - const content = JSON.parse(host.readFile(typesRegistryFilePath)!); + const content = JSON.parse(host.readFile(typesRegistryFilePath)!); return createMapFromTemplate(content.entries); } catch (e) { diff --git a/src/typingsInstallerCore/typingsInstaller.ts b/src/typingsInstallerCore/typingsInstaller.ts index 9be3411446977..115af22bdc677 100644 --- a/src/typingsInstallerCore/typingsInstaller.ts +++ b/src/typingsInstallerCore/typingsInstaller.ts @@ -215,8 +215,8 @@ namespace ts.server.typingsInstaller { this.log.writeLine(`Trying to find '${packageJson}'...`); } if (this.installTypingHost.fileExists(packageJson) && this.installTypingHost.fileExists(packageLockJson)) { - const npmConfig = JSON.parse(this.installTypingHost.readFile(packageJson)!); // TODO: GH#18217 - const npmLock = JSON.parse(this.installTypingHost.readFile(packageLockJson)!); // TODO: GH#18217 + const npmConfig = JSON.parse(this.installTypingHost.readFile(packageJson)!); // TODO: GH#18217 + const npmLock = JSON.parse(this.installTypingHost.readFile(packageLockJson)!); // TODO: GH#18217 if (this.log.isEnabled()) { this.log.writeLine(`Loaded content of '${packageJson}': ${JSON.stringify(npmConfig)}`); this.log.writeLine(`Loaded content of '${packageLockJson}'`); diff --git a/tests/baselines/reference/1.0lib-noErrors.js b/tests/baselines/reference/1.0lib-noErrors.js index 3dac98d9e5647..e10d899b0db55 100644 --- a/tests/baselines/reference/1.0lib-noErrors.js +++ b/tests/baselines/reference/1.0lib-noErrors.js @@ -1,4 +1,4 @@ -//// [1.0lib-noErrors.ts] +//// [1.0lib-noErrors.ts] /* ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use @@ -936,7 +936,7 @@ interface JSON { * @param reviver A function that transforms the results. This function is called for each member of the object. * If a member contains nested objects, the nested objects are transformed before the parent object is. */ - parse(text: string, reviver?: (key: any, value: any) => any): any; + Wparse(text: string, reviver?: (this: any, key: string, value: any) => any): T; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. @@ -1141,21 +1141,22 @@ declare var Array: { (...items: T[]): T[]; isArray(arg: any): boolean; prototype: Array; -} - -//// [1.0lib-noErrors.js] -/* ***************************************************************************** -Copyright (c) Microsoft Corporation. All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); you may not use -this file except in compliance with the License. You may obtain a copy of the -License at http://www.apache.org/licenses/LICENSE-2.0 - -THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED -WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -MERCHANTABLITY OR NON-INFRINGEMENT. - -See the Apache Version 2.0 License for specific language governing permissions -and limitations under the License. -***************************************************************************** */ -/// +} + + +//// [1.0lib-noErrors.js] +/* ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ +/// diff --git a/tests/baselines/reference/controlFlowIfStatement.types b/tests/baselines/reference/controlFlowIfStatement.types index 85b040825049d..d0f3d0fbf5bbd 100644 --- a/tests/baselines/reference/controlFlowIfStatement.types +++ b/tests/baselines/reference/controlFlowIfStatement.types @@ -100,10 +100,10 @@ function c(data: string | T): T { >'string' : "string" return JSON.parse(data); ->JSON.parse(data) : any ->JSON.parse : (text: string, reviver?: (this: any, key: string, value: any) => any) => any +>JSON.parse(data) : T +>JSON.parse : (text: string, reviver?: (this: any, key: string, value: any) => any) => T >JSON : JSON ->parse : (text: string, reviver?: (this: any, key: string, value: any) => any) => any +>parse : (text: string, reviver?: (this: any, key: string, value: any) => any) => T >data : string | (T & string) } else { diff --git a/tests/cases/conformance/decorators/1.0lib-noErrors.ts b/tests/cases/conformance/decorators/1.0lib-noErrors.ts index 391c0926a82b7..33d013a3b53b3 100644 --- a/tests/cases/conformance/decorators/1.0lib-noErrors.ts +++ b/tests/cases/conformance/decorators/1.0lib-noErrors.ts @@ -936,7 +936,7 @@ interface JSON { * @param reviver A function that transforms the results. This function is called for each member of the object. * If a member contains nested objects, the nested objects are transformed before the parent object is. */ - parse(text: string, reviver?: (key: any, value: any) => any): any; + parse(text: string, reviver?: (this: any, key: string, value: any) => any): T; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted. @@ -1141,4 +1141,4 @@ declare var Array: { (...items: T[]): T[]; isArray(arg: any): boolean; prototype: Array; -} \ No newline at end of file +} diff --git a/tests/lib/lib.d.ts b/tests/lib/lib.d.ts index 3fc9d1bd09e74..37843fa89c0d7 100644 --- a/tests/lib/lib.d.ts +++ b/tests/lib/lib.d.ts @@ -974,7 +974,7 @@ interface JSON { * @param reviver A function that transforms the results. This function is called for each member of the object. * If a member contains nested objects, the nested objects are transformed before the parent object is. */ - parse(text: string, reviver?: (key: any, value: any) => any): any; + parse(text: string, reviver?: (this: any, key: string, value: any) => any): T; /** * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. * @param value A JavaScript value, usually an object or array, to be converted.