Skip to content

Commit 2af90ac

Browse files
YovachUzlopak
andauthored
fix(types): websocketPlugin is not an existing variable (#269)
* fix: websocketPlugin is not an existing variable * test: add named-import.test-d.ts * fix typings DRY --------- Co-authored-by: uzlopak <[email protected]>
1 parent d7adb45 commit 2af90ac

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ declare namespace fastifyWebsocket {
103103
Logger extends FastifyBaseLogger = FastifyBaseLogger
104104
> extends fastify.RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>, WebsocketRouteOptions<RawServer, RawRequest, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> { }
105105

106-
export const websocketPlugin: FastifyWebsocket
107-
export { websocketPlugin as default }
106+
export const fastifyWebsocket: FastifyWebsocket
107+
export { fastifyWebsocket as default }
108108
}
109109

110110
declare function fastifyWebsocket(...params: Parameters<FastifyWebsocket>): ReturnType<FastifyWebsocket>

types/index.test-d.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import wsPlugin, { WebsocketHandler, SocketStream } from '..';
1+
import fastifyWebsocket, { WebsocketHandler, SocketStream, fastifyWebsocket as namedFastifyWebsocket, default as defaultFastifyWebsocket } from '..';
22
import type { IncomingMessage } from "http";
33
import fastify, { RouteOptions, FastifyRequest, FastifyInstance, FastifyReply, RequestGenericInterface, FastifyBaseLogger, RawServerDefault, FastifySchema, RawRequestDefaultExpression, RawServerBase, ContextConfigDefault, RawReplyDefaultExpression } from 'fastify';
44
import { expectType } from 'tsd';
@@ -9,10 +9,10 @@ import { Static, Type } from '@sinclair/typebox'
99
import { ResolveFastifyRequestType } from 'fastify/types/type-provider';
1010

1111
const app: FastifyInstance = fastify();
12-
app.register(wsPlugin);
13-
app.register(wsPlugin, {});
14-
app.register(wsPlugin, { options: { maxPayload: 123 } });
15-
app.register(wsPlugin, {
12+
app.register(fastifyWebsocket);
13+
app.register(fastifyWebsocket, {});
14+
app.register(fastifyWebsocket, { options: { maxPayload: 123 } });
15+
app.register(fastifyWebsocket, {
1616
errorHandler: function errorHandler(error: Error, connection: SocketStream, request: FastifyRequest, reply: FastifyReply): void {
1717
expectType<FastifyInstance>(this);
1818
expectType<Error>(error)
@@ -21,9 +21,9 @@ app.register(wsPlugin, {
2121
expectType<FastifyReply>(reply)
2222
}
2323
});
24-
app.register(wsPlugin, { options: { perMessageDeflate: true } });
25-
app.register(wsPlugin, { preClose: function syncPreclose() {} });
26-
app.register(wsPlugin, { preClose: async function asyncPreclose(){} });
24+
app.register(fastifyWebsocket, { options: { perMessageDeflate: true } });
25+
app.register(fastifyWebsocket, { preClose: function syncPreclose() {} });
26+
app.register(fastifyWebsocket, { preClose: async function asyncPreclose(){} });
2727

2828
app.get('/websockets-via-inferrence', { websocket: true }, async function (connection, request) {
2929
expectType<FastifyInstance>(this);
@@ -197,4 +197,8 @@ server.get('/websockets-no-type-inference',
197197
expectType<unknown>(request.body);
198198
expectType<unknown>(request.query);
199199
expectType<IncomingMessage['headers']>(request.headers);
200-
});
200+
});
201+
202+
expectType<typeof fastifyWebsocket>(namedFastifyWebsocket);
203+
expectType<typeof fastifyWebsocket>(defaultFastifyWebsocket);
204+

0 commit comments

Comments
 (0)