From 49fb5fbe1cf53c4975d9683ff40d01c509f0bf23 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Thu, 6 May 2021 14:30:04 +0200 Subject: [PATCH] Handle missing sapper root element Before this change, upgrading this project to typescript and enabling strict null checks would throw the following error : ``` > @rollup/plugin-typescript TS2322: Type 'Element | null' is not assignable to type 'Node'. Type 'null' is not assignable to type 'Node'. 4 target: document.querySelector("#sapper"), ~~~~~~ src/node_modules/@sapper/index.d.ts:20:32 20 export function start(opts: { target: Node }): Promise; ~~~~~~ The expected type comes from property 'target' which is declared here on type '{ target: Node; }' ``` --- src/client.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client.js b/src/client.js index cec91725..3e97abae 100644 --- a/src/client.js +++ b/src/client.js @@ -1,5 +1,5 @@ import * as sapper from '@sapper/app'; -sapper.start({ - target: document.querySelector('#sapper') -}); \ No newline at end of file +const target = document.querySelector('#sapper'); +if (!target) throw new Error("Missing #sapper element"); +sapper.start({ target });