Skip to content

Commit 96c7785

Browse files
committed
type errors to go with new type fixes in svelte.dev
1 parent 53d575c commit 96c7785

File tree

10 files changed

+49
-22
lines changed

10 files changed

+49
-22
lines changed

documentation/docs/10-getting-started/30-project-structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Project structure
44

55
A typical SvelteKit project looks like this:
66

7-
```bash
7+
```tree
88
my-project/
99
├ src/
1010
│ ├ lib/

documentation/docs/20-core-concepts/30-form-actions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ Note that you need to `deserialize` the response before processing it further us
469469
If you have a `+server.js` alongside your `+page.server.js`, `fetch` requests will be routed there by default. To `POST` to an action in `+page.server.js` instead, use the custom `x-sveltekit-action` header:
470470
471471
```js
472+
// @errors: 2532 2304
472473
const response = await fetch(this.action, {
473474
method: 'POST',
474475
body: data,

documentation/docs/25-build-and-deploy/50-adapter-static.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This will prerender your entire site as a collection of static files. If you'd l
1111
Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `svelte.config.js`:
1212

1313
```js
14-
// @errors: 2307
1514
/// file: svelte.config.js
1615
import adapter from '@sveltejs/adapter-static';
1716

@@ -52,8 +51,10 @@ Some platforms have zero-config support (more to come in future):
5251
On these platforms, you should omit the adapter options so that `adapter-static` can provide the optimal configuration:
5352

5453
```js
55-
// @errors: 2304
5654
/// file: svelte.config.js
55+
import adapter from '@sveltejs/adapter-static';
56+
57+
/** @type {import('@sveltejs/kit').Config} */
5758
const config = {
5859
kit: {
5960
adapter: adapter(---{...}---)
@@ -94,7 +95,7 @@ You'll also want to generate a fallback `404.html` page to replace the default 4
9495
A config for GitHub Pages might look like the following:
9596

9697
```js
97-
// @errors: 2307 2322
98+
// @errors: 2322
9899
/// file: svelte.config.js
99100
import adapter from '@sveltejs/adapter-static';
100101

documentation/docs/25-build-and-deploy/55-single-page-apps.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ If you don't have any server-side logic (i.e. `+page.server.js`, `+layout.server
1818
Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `svelte.config.js` with the following options:
1919

2020
```js
21-
// @errors: 2307
2221
/// file: svelte.config.js
2322
import adapter from '@sveltejs/adapter-static';
2423

documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,25 @@ Functions contained in the [`/functions` directory](https://developers.cloudflar
128128
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/context/), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties), meaning that you can access it in hooks and endpoints:
129129

130130
```js
131-
// @errors: 7031
131+
// @filename: ambient.d.ts
132+
import { DurableObjectNamespace } from '@cloudflare/workers-types';
133+
134+
declare global {
135+
namespace App {
136+
interface Platform {
137+
env: {
138+
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
139+
};
140+
}
141+
}
142+
}
143+
// @filename: +server.js
144+
// ---cut---
145+
// @errors: 2355 2322
132146
/// file: +server.js
133147
/** @type {import('./$types').RequestHandler} */
134148
export async function POST({ request, platform }) {
135-
const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
149+
const x = platform?.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
136150
}
137151
```
138152
@@ -147,7 +161,7 @@ To make these types available to your app, install [`@cloudflare/workers-types`]
147161
declare global {
148162
namespace App {
149163
interface Platform {
150-
+++ env?: {
164+
+++ env: {
151165
YOUR_KV_NAMESPACE: KVNamespace;
152166
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
153167
};+++
@@ -198,6 +212,7 @@ Cloudflare no longer recommends using [Workers Sites](https://developers.cloudfl
198212
### svelte.config.js
199213
200214
```js
215+
// @errors: 2307
201216
/// file: svelte.config.js
202217
---import adapter from '@sveltejs/adapter-cloudflare-workers';---
203218
+++import adapter from '@sveltejs/adapter-cloudflare';+++

documentation/docs/25-build-and-deploy/70-adapter-cloudflare-workers.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,25 @@ wrangler deploy
8383
The [`env`](https://developers.cloudflare.com/workers/runtime-apis/fetch-event#parameters) object contains your project's [bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/), which consist of KV/DO namespaces, etc. It is passed to SvelteKit via the `platform` property, along with [`context`](https://developers.cloudflare.com/workers/runtime-apis/context/), [`caches`](https://developers.cloudflare.com/workers/runtime-apis/cache/), and [`cf`](https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties), meaning that you can access it in hooks and endpoints:
8484

8585
```js
86-
// @errors: 7031
86+
// @filename: ambient.d.ts
87+
import { DurableObjectNamespace } from '@cloudflare/workers-types';
88+
89+
declare global {
90+
namespace App {
91+
interface Platform {
92+
env: {
93+
YOUR_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
94+
};
95+
}
96+
}
97+
}
98+
// @filename: +server.js
99+
// ---cut---
100+
// @errors: 2355 2322
87101
/// file: +server.js
88102
/** @type {import('./$types').RequestHandler} */
89103
export async function POST({ request, platform }) {
90-
const x = platform.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
104+
const x = platform?.env.YOUR_DURABLE_OBJECT_NAMESPACE.idFromName('x');
91105
}
92106
```
93107

documentation/docs/25-build-and-deploy/80-adapter-netlify.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This adapter will be installed by default when you use [`adapter-auto`](adapter-
1111
Install with `npm i -D @sveltejs/adapter-netlify`, then add the adapter to your `svelte.config.js`:
1212

1313
```js
14-
// @errors: 2307
1514
/// file: svelte.config.js
1615
import adapter from '@sveltejs/adapter-netlify';
1716

@@ -54,7 +53,6 @@ New projects will use the current Node LTS version by default. However, if you'r
5453
SvelteKit supports [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to Node-based Netlify Functions.
5554

5655
```js
57-
// @errors: 2307
5856
/// file: svelte.config.js
5957
import adapter from '@sveltejs/adapter-netlify';
6058

@@ -98,11 +96,14 @@ During compilation, redirect rules are automatically appended to your `_redirect
9896
With this adapter, SvelteKit endpoints are hosted as [Netlify Functions](https://docs.netlify.com/functions/overview/). Netlify function handlers have additional context, including [Netlify Identity](https://docs.netlify.com/visitor-access/identity/) information. You can access this context via the `event.platform.context` field inside your hooks and `+page.server` or `+layout.server` endpoints. These are [serverless functions](https://docs.netlify.com/functions/overview/) when the `edge` property is `false` in the adapter config or [edge functions](https://docs.netlify.com/edge-functions/overview/#app) when it is `true`.
9997

10098
```js
101-
// @errors: 2705 7006
99+
// @filename: ambient.d.ts
100+
/// <reference types="@sveltejs/adapter-netlify" />
101+
// @filename: +page.server.js
102+
// ---cut---
102103
/// file: +page.server.js
103104
/** @type {import('./$types').PageServerLoad} */
104105
export const load = async (event) => {
105-
const context = event.platform.context;
106+
const context = event.platform?.context;
106107
console.log(context); // shows up in your functions log in the Netlify app
107108
};
108109
```

documentation/docs/25-build-and-deploy/90-adapter-vercel.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This adapter will be installed by default when you use [`adapter-auto`](adapter-
1111
Install with `npm i -D @sveltejs/adapter-vercel`, then add the adapter to your `svelte.config.js`:
1212

1313
```js
14-
// @errors: 2307 2345
1514
/// file: svelte.config.js
1615
import adapter from '@sveltejs/adapter-vercel';
1716

@@ -101,7 +100,6 @@ Vercel supports [Incremental Static Regeneration](https://vercel.com/docs/increm
101100
To add ISR to a route, include the `isr` property in your `config` object:
102101

103102
```js
104-
// @errors: 2664
105103
import { BYPASS_TOKEN } from '$env/static/private';
106104

107105
/** @type {import('@sveltejs/adapter-vercel').Config} */
@@ -153,7 +151,6 @@ A list of valid query parameters that contribute to the cache key. Other paramet
153151
Vercel makes a set of [deployment-specific environment variables](https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables) available. Like other environment variables, these are accessible from `$env/static/private` and `$env/dynamic/private` (sometimes — more on that later), and inaccessible from their public counterparts. To access one of these variables from the client:
154152

155153
```js
156-
// @errors: 2305
157154
/// file: +layout.server.js
158155
import { VERCEL_COMMIT_REF } from '$env/static/private';
159156

documentation/docs/30-advanced/20-hooks.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ This function runs once, when the server is created or the app starts in the bro
249249
> [!NOTE] If your environment supports top-level await, the `init` function is really no different from writing your initialisation logic at the top level of the module, but some environments — most notably, Safari — don't.
250250
251251
```js
252+
// @errors: 2307
252253
/// file: src/hooks.server.js
253254
import * as db from '$lib/server/database';
254255

@@ -272,9 +273,8 @@ This function runs before `handle` and allows you to change how URLs are transla
272273
For example, you might have a `src/routes/[[lang]]/about/+page.svelte` page, which should be accessible as `/en/about` or `/de/ueber-uns` or `/fr/a-propos`. You could implement this with `reroute`:
273274

274275
```js
276+
// @errors: 2345 2304
275277
/// file: src/hooks.js
276-
// @errors: 2345
277-
// @errors: 2304
278278

279279
/** @type {Record<string, string>} */
280280
const translated = {
@@ -298,9 +298,8 @@ Using `reroute` will _not_ change the contents of the browser's address bar, or
298298
Since version 2.18, the `reroute` hook can be asynchronous, allowing it to (for example) fetch data from your backend to decide where to reroute to. Use this carefully and make sure it's fast, as it will delay navigation otherwise. If you need to fetch data, use the `fetch` provided as an argument. It has the [same benefits](load#Making-fetch-requests) as the `fetch` provided to `load` functions, with the caveat that `params` and `id` are unavailable to [`handleFetch`](#Server-hooks-handleFetch) because the route is not yet known.
299299

300300
```js
301+
// @errors: 2345 2304
301302
/// file: src/hooks.js
302-
// @errors: 2345`
303-
// @errors: 2304
304303

305304
/** @type {import('@sveltejs/kit').Reroute} */
306305
export async function reroute({ url, fetch }) {
@@ -323,6 +322,7 @@ export async function reroute({ url, fetch }) {
323322
This is a collection of _transporters_, which allow you to pass custom types — returned from `load` and form actions — across the server/client boundary. Each transporter contains an `encode` function, which encodes values on the server (or returns a falsy value for anything that isn't an instance of the type) and a corresponding `decode` function:
324323

325324
```js
325+
// @errors: 2307
326326
/// file: src/hooks.js
327327
import { Vector } from '$lib/math';
328328

documentation/docs/30-advanced/40-service-workers.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Inside the service worker you have access to the [`$service-worker` module]($ser
2323
The following example caches the built app and any files in `static` eagerly, and caches all other requests as they happen. This would make each page work offline once visited.
2424

2525
```js
26-
// @errors: 2339
2726
/// file: src/service-worker.js
2827
// Disables access to DOM typings like `HTMLElement` which are not available
2928
// inside a service worker and instantiates the correct globals

0 commit comments

Comments
 (0)