From 76d24be5c04db9b9f1267a6df5cd29d528a929bf Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Sat, 16 May 2020 10:50:45 +1000 Subject: [PATCH 1/2] types: fix typing for options.attachTo --- src/mount.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 3e4016943..b59e72604 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -86,9 +86,12 @@ export function mount( el.id = MOUNT_ELEMENT_ID if (options?.attachTo) { - const to = isString(options.attachTo) - ? document.querySelector(options.attachTo) - : options.attachTo + let to: Element + if (typeof options.attachTo === 'string') { + to = document.querySelector(options.attachTo) + } else { + to = options.attachTo + } if (!to) { throw new Error( From 8e36df46d2e3b0664aea8a1c9cfe220c0c16cceb Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Sat, 16 May 2020 10:58:59 +1000 Subject: [PATCH 2/2] refactor: move check inside if statement --- src/mount.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index b59e72604..13348217e 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -89,15 +89,15 @@ export function mount( let to: Element if (typeof options.attachTo === 'string') { to = document.querySelector(options.attachTo) + if (!to) { + throw new Error( + `Unable to find the element matching the selector ${options.attachTo} given as the \`attachTo\` option` + ) + } } else { to = options.attachTo } - if (!to) { - throw new Error( - `Unable to find the element matching the selector ${options.attachTo} given as the \`attachTo\` option` - ) - } to.appendChild(el) }