Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate TS with satisfies #8001

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/docs/20-core-concepts/20-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export async function load({ cookies }) {
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:

```js
// @errors: 2322
// @errors: 2322 1360
/// file: src/routes/products/+page.js
/** @type {import('./$types').PageLoad} */
export async function load({ fetch, setHeaders }) {
Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/30-advanced/20-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ declare namespace App {

```js
/// file: src/hooks.server.js
// @errors: 2322 2571 2339
// @errors: 2322 1360 2571 2339
// @filename: ambient.d.ts
const Sentry: any;

Expand All @@ -177,7 +177,7 @@ export function handleError({ error, event }) {

```js
/// file: src/hooks.client.js
// @errors: 2322 2571 2339
// @errors: 2322 1360 2571 2339
// @filename: ambient.d.ts
const Sentry: any;

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/30-advanced/25-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Unexpected errors will go through the [`handleError`](/docs/hooks#shared-hooks-h

```js
/// file: src/hooks.server.js
// @errors: 2322 2571 2339
// @errors: 2322 1360 2571 2339
// @filename: ambient.d.ts
const Sentry: any;

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/50-reference/40-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The `RequestHandler` and `Load` types both accept a `Params` argument allowing y

```js
/// file: src/routes/[foo]/[bar]/[baz]/+page.server.js
// @errors: 2355 2322
// @errors: 2355 2322 1360
/** @type {import('@sveltejs/kit').RequestHandler<{
* foo: string;
* bar: string;
Expand Down
3 changes: 2 additions & 1 deletion sites/kit.svelte.dev/src/lib/docs/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,12 @@ function convert_to_ts(js_code, indent = '', offset = '') {
code.overwrite(
node.getStart(),
node.name.getEnd(),
`${is_export ? 'export ' : ''}const ${node.name.getText()}: ${name} = ${
`${is_export ? 'export ' : ''}const ${node.name.getText()} = (${
is_async ? 'async ' : ''
}`
);
code.appendLeft(node.body.getStart(), '=> ');
code.appendLeft(node.body.getEnd(), `) satisfies ${name};`);

modified = true;
} else if (
Expand Down
6 changes: 3 additions & 3 deletions sites/kit.svelte.dev/src/lib/docs/server/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ export function GET(event) {
\`\`\`generated-ts
// @errors: 2461
/// file: src/routes/what-is-my-user-agent/+server.ts
import type { RequestHandler } from './$types';
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';

export const GET: RequestHandler = (event) => {
export const GET = ((event) => {
// log all headers
console.log(...event.request.headers);

return json({
// retrieve a specific header
userAgent: event.request.headers.get('user-agent')
});
}
}) satisfies RequestHandler;
\`\`\`

etc etc
Expand Down