Skip to content

Commit

Permalink
create-svelte: Fix hooks tsc warnings on strictest typescript config
Browse files Browse the repository at this point in the history
Error: Module '@types/cookie/index' has no default export. ts(1192)
Error: Property 'userid' comes from an index signature, so it must be accessed with ['userid']. ts(4111)

Strictest tsconfig from https://github.com/tsconfig/bases/blob/27f9097a02f960e351d69bca8dd4c7581d70e1b6/bases/strictest.json
  • Loading branch information
Nicolas Le Cam committed Apr 20, 2022
1 parent 2813974 commit 3b2bce2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-pigs-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Make hooks file comply with TypeScript strictest mode
6 changes: 3 additions & 3 deletions packages/create-svelte/templates/default/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import cookie from 'cookie';
import { v4 as uuid } from '@lukeed/uuid';
import type { Handle } from '@sveltejs/kit';
import * as cookie from 'cookie';

/** @type {import('@sveltejs/kit').Handle} */
export const handle: Handle = async ({ event, resolve }) => {
const cookies = cookie.parse(event.request.headers.get('cookie') || '');
event.locals.userid = cookies.userid || uuid();
event.locals.userid = cookies['userid'] || uuid();

const response = await resolve(event);

if (!cookies.userid) {
if (!cookies['userid']) {
// if this is the first time the user has visited this app,
// set a cookie so that we recognise them when they return
response.headers.set(
Expand Down

0 comments on commit 3b2bce2

Please sign in to comment.