From c78f0aab6fc5670c978dbeab7f175230985fd5be Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:55:24 -0500 Subject: [PATCH] fix(xml): use the type system to verify version Reverts: 78ed4ac2a1641c208844600c0fbea4b23bbd0b06 --- xml/_types.ts | 4 ++-- xml/_types_test.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/xml/_types.ts b/xml/_types.ts index a7630ce..d29b61e 100644 --- a/xml/_types.ts +++ b/xml/_types.ts @@ -25,11 +25,11 @@ export type xml_node = { /** XML document. */ export type xml_document = xml_node & { /** XML version. */ - ["@version"]?: string + ["@version"]?: `1.${number}` /** XML character encoding. */ ["@encoding"]?: string /** XML standalone. */ - ["@standalone"]?: string + ["@standalone"]?: "yes" | "no" /** XML doctype. */ ["#doctype"]?: xml_node /** XML instructions. */ diff --git a/xml/_types_test.ts b/xml/_types_test.ts index 0d89806..4abd82d 100644 --- a/xml/_types_test.ts +++ b/xml/_types_test.ts @@ -1 +1,18 @@ import "./_types.ts" +import { stringify } from "./mod.ts" + +// Verify that the generic type is correctly inferred. +const _example = stringify({ + "@version": "1.1", + "@encoding": "UTF-8", + "@standalone": "yes", + "#doctype": { + "~name": "html", + "~children": [], + "#text": "", + }, + "#instructions": {}, + "~name": "html", + "~children": [], + "#text": "", +})