From 90f8dbece3acdc9a94d9c5c8baaca439fd316b67 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 26 Jul 2021 10:18:49 -0700 Subject: [PATCH 1/2] [chore] typecheck example --- examples/hn.svelte.dev/src/routes/[list]/rss.js | 11 +++++++++-- examples/hn.svelte.dev/src/routes/rss.js | 12 +++++++++--- examples/hn.svelte.dev/tsconfig.json | 10 ++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/examples/hn.svelte.dev/src/routes/[list]/rss.js b/examples/hn.svelte.dev/src/routes/[list]/rss.js index 77deb67b00cb..eb03997ad1d5 100644 --- a/examples/hn.svelte.dev/src/routes/[list]/rss.js +++ b/examples/hn.svelte.dev/src/routes/[list]/rss.js @@ -1,3 +1,7 @@ +/** + * @param {string} list + * @param {Record[]} items + */ const render = (list, items) => ` @@ -27,9 +31,12 @@ const render = (list, items) => ` `; -export function get(req, res) { +/** + * @type {import('@sveltejs/kit').RequestHandler} + */ +export function get({params}) { const list = - req.params.list === 'top' ? 'news' : req.params.list === 'new' ? 'newest' : req.params.list; + params.list === 'top' ? 'news' : params.list === 'new' ? 'newest' : params.list; fetch(`https://api.hnpwa.com/v0/${list}/1.json`) .then((r) => r.json()) diff --git a/examples/hn.svelte.dev/src/routes/rss.js b/examples/hn.svelte.dev/src/routes/rss.js index deaf009f347e..212ad1818627 100644 --- a/examples/hn.svelte.dev/src/routes/rss.js +++ b/examples/hn.svelte.dev/src/routes/rss.js @@ -1,3 +1,9 @@ -export function get(req, res) { - res.redirect('/top/rss'); -} \ No newline at end of file +/** + * @type {import('@sveltejs/kit').RequestHandler} + */ +export function get() { + return { + headers: { Location: '/top/rss' }, + status: 301 + }; +} diff --git a/examples/hn.svelte.dev/tsconfig.json b/examples/hn.svelte.dev/tsconfig.json index 7362a3b82462..62c15fcff318 100644 --- a/examples/hn.svelte.dev/tsconfig.json +++ b/examples/hn.svelte.dev/tsconfig.json @@ -1,8 +1,14 @@ { "compilerOptions": { + "allowJs": true, + "checkJs": true, + "noEmit": true, + "strict": true, "baseUrl": ".", "paths": { - "$lib/*": ["./src/lib/*"] + "$lib": ["src/lib"], + "$lib/*": ["src/lib/*"] } - } + }, + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] } From 16b7b1c1ad46c13c574ec0ed42225af08d761c40 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 27 Jul 2021 12:05:55 -0700 Subject: [PATCH 2/2] spacing --- examples/hn.svelte.dev/src/routes/[list]/rss.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/hn.svelte.dev/src/routes/[list]/rss.js b/examples/hn.svelte.dev/src/routes/[list]/rss.js index eb03997ad1d5..f98d0c286796 100644 --- a/examples/hn.svelte.dev/src/routes/[list]/rss.js +++ b/examples/hn.svelte.dev/src/routes/[list]/rss.js @@ -1,6 +1,6 @@ /** * @param {string} list - * @param {Record[]} items + * @param {Record[]} items */ const render = (list, items) => ` @@ -34,7 +34,7 @@ const render = (list, items) => ` /** * @type {import('@sveltejs/kit').RequestHandler} */ -export function get({params}) { +export function get({ params }) { const list = params.list === 'top' ? 'news' : params.list === 'new' ? 'newest' : params.list;