🤖 Merge PR #46722 xml2json: replace types of {} with Record<string, unknown> by @garyking

* use Record

# Conflicts:
#	types/xml2json/index.d.ts

* fix

* use generics

* fix lint errors from using generics only once
This commit is contained in:
garyking 2020-08-16 18:24:19 -04:00 committed by GitHub
parent d8fc3f8dcf
commit d4e7c79bb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -7,9 +7,9 @@
/// <reference types="node" />
export function toJson(xml: string | Buffer, options?: { object?: false } & JsonOptions): string;
export function toJson(xml: string | Buffer, options?: { object: true } & JsonOptions): {};
export function toJson(xml: string | Buffer, options?: { object: true } & JsonOptions): { [key: string]: unknown };
export function toXml(json: {} | string | Buffer, options?: XmlOptions): string;
export function toXml(json: { [key: string]: unknown } | string | Buffer, options?: XmlOptions): string;
export interface XmlOptions {
/**

View File

@ -9,7 +9,7 @@ const jsonString: string = parser.toJson(xml);
xml = parser.toXml(jsonString);
// xml to json in object mode and JsonOptions
const jsonObject: {} = parser.toJson(xml, {
const jsonObject: { [key: string]: unknown } = parser.toJson(xml, {
object: true,
reversible: false,
coerce: false,
@ -18,6 +18,9 @@ const jsonObject: {} = parser.toJson(xml, {
arrayNotation: false,
});
const a = parser.toJson(xml, { object: true }) as { [key: string]: string };
const b = parser.toJson(xml, { object: true }) as { [key: string]: number };
// json to xml with XmlOptions
xml = parser.toXml(jsonObject, {
sanitize: true,