Skip to content

Commit

Permalink
move types to types folder and fix typing (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Aug 8, 2022
1 parent f6ffc7b commit 9dad9b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "6.5.0",
"description": "Plugin for serving static files as fast as possible.",
"main": "index.js",
"types": "index.d.ts",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard | snazzy",
"lint:fix": "standard --fix",
Expand Down Expand Up @@ -53,8 +53,7 @@
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tsd": "^0.22.0",
"typescript": "^4.0.2"
"tsd": "^0.22.0"
},
"tsd": {
"directory": "test/types"
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts → types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Leo <https://github.com/leomelzer>
/// <reference types="node" />

import { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify';
import { FastifyPluginAsync, FastifyRequest } from 'fastify';
import { Stats } from 'fs';

declare module "fastify" {
Expand All @@ -16,7 +16,7 @@ declare module "fastify" {
}
}

type FastifyStaticPlugin = FastifyPluginCallback<NonNullable<fastifyStatic.FastifyStaticOptions>>;
type FastifyStaticPlugin = FastifyPluginAsync<NonNullable<fastifyStatic.FastifyStaticOptions>>;

declare namespace fastifyStatic {
export interface ExtendedInformation {
Expand Down
22 changes: 11 additions & 11 deletions test/types/index.ts → types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import fastify, { FastifyInstance, FastifyPluginCallback, FastifyRequest } from 'fastify'
import fastify, { FastifyInstance, FastifyPluginAsync, FastifyRequest } from 'fastify'
import { Server } from 'http';
import { expectAssignable, expectError, expectType } from 'tsd'
import * as fastifyStaticStar from '../..';
import * as fastifyStaticStar from '..';
import fastifyStatic, {
FastifyStaticOptions,
fastifyStatic as fastifyStaticNamed,
} from '../..'
} from '..'

import fastifyStaticCjsImport = require('../..');
const fastifyStaticCjs = require('../..');
import fastifyStaticCjsImport = require('..');
const fastifyStaticCjs = require('..');

const app: FastifyInstance = fastify();

Expand All @@ -20,12 +20,12 @@ app.register(fastifyStaticCjsImport.fastifyStatic);
app.register(fastifyStaticStar.default);
app.register(fastifyStaticStar.fastifyStatic);

expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStatic);
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticNamed);
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticCjsImport.default);
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticCjsImport.fastifyStatic);
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticStar.default);
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(
expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(fastifyStatic);
expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(fastifyStaticNamed);
expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(fastifyStaticCjsImport.default);
expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(fastifyStaticCjsImport.fastifyStatic);
expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(fastifyStaticStar.default);
expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(
fastifyStaticStar.fastifyStatic
);
expectType<any>(fastifyStaticCjs);
Expand Down

0 comments on commit 9dad9b0

Please sign in to comment.