Skip to content

Commit

Permalink
improve type test readability
Browse files Browse the repository at this point in the history
  • Loading branch information
zetaraku committed Jul 3, 2024
1 parent c3df531 commit e8bdb38
Showing 1 changed file with 6 additions and 6 deletions.
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'))
})
})

0 comments on commit e8bdb38

Please sign in to comment.