Skip to content

Commit a22fb66

Browse files
authored
generate TS with satisfies (#8001)
1 parent 132a5de commit a22fb66

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

Diff for: documentation/docs/20-core-concepts/20-load.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export async function load({ cookies }) {
271271
Both server-only and shared `load` functions have access to a `setHeaders` function that, when running on the server, can set headers for the response. (When running in the browser, `setHeaders` has no effect.) This is useful if you want the page to be cached, for example:
272272

273273
```js
274-
// @errors: 2322
274+
// @errors: 2322 1360
275275
/// file: src/routes/products/+page.js
276276
/** @type {import('./$types').PageLoad} */
277277
export async function load({ fetch, setHeaders }) {

Diff for: documentation/docs/30-advanced/20-hooks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ declare namespace App {
157157

158158
```js
159159
/// file: src/hooks.server.js
160-
// @errors: 2322 2571 2339
160+
// @errors: 2322 1360 2571 2339
161161
// @filename: ambient.d.ts
162162
const Sentry: any;
163163

@@ -177,7 +177,7 @@ export function handleError({ error, event }) {
177177
178178
```js
179179
/// file: src/hooks.client.js
180-
// @errors: 2322 2571 2339
180+
// @errors: 2322 1360 2571 2339
181181
// @filename: ambient.d.ts
182182
const Sentry: any;
183183

Diff for: documentation/docs/30-advanced/25-errors.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Unexpected errors will go through the [`handleError`](/docs/hooks#shared-hooks-h
8181

8282
```js
8383
/// file: src/hooks.server.js
84-
// @errors: 2322 2571 2339
84+
// @errors: 2322 1360 2571 2339
8585
// @filename: ambient.d.ts
8686
const Sentry: any;
8787

Diff for: documentation/docs/50-reference/40-types.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The `RequestHandler` and `Load` types both accept a `Params` argument allowing y
2020

2121
```js
2222
/// file: src/routes/[foo]/[bar]/[baz]/+page.server.js
23-
// @errors: 2355 2322
23+
// @errors: 2355 2322 1360
2424
/** @type {import('@sveltejs/kit').RequestHandler<{
2525
* foo: string;
2626
* bar: string;

Diff for: sites/kit.svelte.dev/src/lib/docs/server/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,12 @@ function convert_to_ts(js_code, indent = '', offset = '') {
463463
code.overwrite(
464464
node.getStart(),
465465
node.name.getEnd(),
466-
`${is_export ? 'export ' : ''}const ${node.name.getText()}: ${name} = ${
466+
`${is_export ? 'export ' : ''}const ${node.name.getText()} = (${
467467
is_async ? 'async ' : ''
468468
}`
469469
);
470470
code.appendLeft(node.body.getStart(), '=> ');
471+
code.appendLeft(node.body.getEnd(), `) satisfies ${name};`);
471472

472473
modified = true;
473474
} else if (

Diff for: sites/kit.svelte.dev/src/lib/docs/server/index.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ export function GET(event) {
5959
\`\`\`generated-ts
6060
// @errors: 2461
6161
/// file: src/routes/what-is-my-user-agent/+server.ts
62-
import type { RequestHandler } from './$types';
6362
import { json } from '@sveltejs/kit';
63+
import type { RequestHandler } from './$types';
6464
65-
export const GET: RequestHandler = (event) => {
65+
export const GET = ((event) => {
6666
// log all headers
6767
console.log(...event.request.headers);
6868
6969
return json({
7070
// retrieve a specific header
7171
userAgent: event.request.headers.get('user-agent')
7272
});
73-
}
73+
}) satisfies RequestHandler;
7474
\`\`\`
7575
7676
etc etc

0 commit comments

Comments
 (0)