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

improve type test readability #259

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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
12 changes: 6 additions & 6 deletions types/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fastify, {
Session
} from 'fastify';
import Redis from 'ioredis';
import { expectAssignable, expectDocCommentIncludes, expectError, expectType } from 'tsd';
import { expectAssignable, expectNotAssignable, expectDocCommentIncludes, expectError, expectType } from 'tsd';
import { CookieOptions, MemoryStore, SessionStore, default as fastifySession, default as plugin } from '..';

class EmptyStore {
Expand Down Expand Up @@ -144,11 +144,11 @@ const app2 = fastify()
app2.register(fastifySession)

app2.get('/', async function(request) {
let num: number | undefined, str: string | undefined;
expectError(num = request.session.get('foo'));
expectAssignable(str = request.session.get('foo'));
expectAssignable<string | undefined>(request.session.get('foo'));
expectNotAssignable<number | undefined>(request.session.get('foo'));

expectType<void>(request.session.set('foo', 'bar'));
expectError(request.session.set('foo', 2));
expectAssignable(request.session.set('foo', 'bar'));

expectType<undefined | { id: number }>(request.session.get('user'))
expectAssignable(request.session.set('user', { id: 2 }))
Expand All @@ -158,4 +158,4 @@ app2.get('/', async function(request) {

expectType<any>(request.session.get<any>('not exist'))
expectAssignable(request.session.set<any>('not exist', 'abc'))
})
})