Skip to content

Commit f086f1c

Browse files
committed
Use satifies operator
1 parent 581c43e commit f086f1c

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

Diff for: .changeset/cool-seahorses-cross.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-svelte': patch
3+
---
4+
5+
Use `satisfies` operator

Diff for: packages/create-svelte/templates/default/src/routes/sverdle/+page.server.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { invalid } from '@sveltejs/kit';
2-
import { Game } from './game';
2+
import { words, allowed } from './words.server';
33
import type { PageServerLoad, Actions } from './$types';
44

55
/** @type {import('./$types').PageServerLoad} */
6-
export const load: PageServerLoad = ({ cookies }) => {
6+
export const load = (({ cookies }) => {
77
const game = new Game(cookies.get('sverdle'));
88

99
return {
@@ -23,10 +23,10 @@ export const load: PageServerLoad = ({ cookies }) => {
2323
*/
2424
answer: game.answers.length >= 6 ? game.answer : null
2525
};
26-
};
26+
}) satisfies PageServerLoad;
2727

2828
/** @type {import('./$types').Actions} */
29-
export const actions: Actions = {
29+
export const actions = {
3030
/**
3131
* Modify game state in reaction to a keypress. If client-side JavaScript
3232
* is available, this will happen in the browser instead of here
@@ -68,4 +68,4 @@ export const actions: Actions = {
6868
restart: async ({ cookies }) => {
6969
cookies.delete('sverdle');
7070
}
71-
};
71+
} satisfies Actions;

Diff for: packages/kit/src/core/sync/write_types/index.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,26 @@ test('Rewrites action types for a TypeScript module', () => {
265265
);
266266
});
267267

268+
test('Leaves satisfies operator untouched', () => {
269+
const source = `
270+
import type { Actions, PageServerLoad, RequestEvent } from './$types';
271+
export function load({ params }) {
272+
return {
273+
a: 1
274+
};
275+
} satisfies PageServerLoad
276+
export const actions = {
277+
a: () => {},
278+
b: (param: RequestEvent) => {},
279+
c: (param) => {},
280+
} satisfies Actions
281+
`;
282+
283+
const rewritten = tweak_types(source, true);
284+
285+
assert.equal(rewritten?.exports, ['load', 'actions']);
286+
assert.equal(rewritten?.modified, false);
287+
assert.equal(rewritten?.code, source);
288+
});
289+
268290
test.run();

0 commit comments

Comments
 (0)