Skip to content

Commit d723e87

Browse files
KuShNicolas Le Cam
and
Nicolas Le Cam
authored
create-svelte: Fix hooks tsc warnings on strictest typescript config (#4667)
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 Co-authored-by: Nicolas Le Cam <[email protected]>
1 parent b228fb5 commit d723e87

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

.changeset/healthy-pigs-fly.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-svelte': patch
3+
---
4+
5+
Make hooks file comply with TypeScript strictest mode

packages/create-svelte/templates/default/src/hooks.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import cookie from 'cookie';
21
import { v4 as uuid } from '@lukeed/uuid';
32
import type { Handle } from '@sveltejs/kit';
3+
import * as cookie from 'cookie';
44

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

1010
const response = await resolve(event);
1111

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

0 commit comments

Comments
 (0)