Skip to content

Commit

Permalink
Use satifies operator
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Nov 29, 2022
1 parent 82900bb commit 132a5de
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-seahorses-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Use `satisfies` operator
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Game } from './game';
import type { PageServerLoad, Actions } from './$types';

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

return {
Expand All @@ -23,10 +23,10 @@ export const load: PageServerLoad = ({ cookies }) => {
*/
answer: game.answers.length >= 6 ? game.answer : null
};
};
}) satisfies PageServerLoad;

/** @type {import('./$types').Actions} */
export const actions: Actions = {
export const actions = {
/**
* Modify game state in reaction to a keypress. If client-side JavaScript
* is available, this will happen in the browser instead of here
Expand Down Expand Up @@ -68,4 +68,4 @@ export const actions: Actions = {
restart: async ({ cookies }) => {
cookies.delete('sverdle');
}
};
} satisfies Actions;
22 changes: 22 additions & 0 deletions packages/kit/src/core/sync/write_types/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,26 @@ test('Rewrites action types for a TypeScript module', () => {
);
});

test('Leaves satisfies operator untouched', () => {
const source = `
import type { Actions, PageServerLoad, RequestEvent } from './$types';
export function load({ params }) {
return {
a: 1
};
} satisfies PageServerLoad
export const actions = {
a: () => {},
b: (param: RequestEvent) => {},
c: (param) => {},
} satisfies Actions
`;

const rewritten = tweak_types(source, true);

assert.equal(rewritten?.exports, ['load', 'actions']);
assert.equal(rewritten?.modified, false);
assert.equal(rewritten?.code, source);
});

test.run();

0 comments on commit 132a5de

Please sign in to comment.