Skip to content

Commit

Permalink
fix(types): better streamBuilder types
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Jul 25, 2023
1 parent d02e176 commit 247e187
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/lib/connect/ali.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const buildStream: StreamBuilder = (client, opts) => {

bindEventHandler()

return stream as unknown as Duplex
return stream
}

export default buildStream
5 changes: 1 addition & 4 deletions src/lib/connect/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import _debug from 'debug'
import url from 'url'
import MqttClient, {
IClientOptions,
MqttClientEventCallbacks,
MqttProtocol,
} from '../client'
import IS_BROWSER from '../is-browser'
import Store from '../store'
import DefaultMessageIdProvider from '../default-message-id-provider'
import UniqueMessageIdProvider from '../unique-message-id-provider'
import _debug from 'debug'
import { StreamBuilder } from '../shared'

const debug = _debug('mqttjs')
Expand Down
2 changes: 1 addition & 1 deletion src/lib/connect/tcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const buildStream: StreamBuilder = (client, opts) => {
const host = opts.hostname

debug('port %d and host %s', port, host)
return net.createConnection(port, host) as unknown as Duplex
return net.createConnection(port, host)
}

export default buildStream
2 changes: 1 addition & 1 deletion src/lib/connect/tls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const buildStream: StreamBuilder = (client, opts) => {
}

connection.on('error', handleTLSerrors)
return connection as unknown as Duplex
return connection
}

export default buildStream
7 changes: 3 additions & 4 deletions src/lib/connect/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,12 @@ const streamBuilder: StreamBuilder = (client, opts) => {
socket,
options.wsOptions as DuplexOptions,
)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
webSocketStream.url = url

webSocketStream['url'] = url
socket.on('close', () => {
webSocketStream.destroy()
})
return webSocketStream as Duplex
return webSocketStream
}

const browserStreamBuilder: StreamBuilder = (client, opts) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/connect/wx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const buildStream: StreamBuilder = (client, opts) => {

bindEventHandler()

return stream as unknown as Duplex
return stream
}

export default buildStream
8 changes: 4 additions & 4 deletions src/lib/shared.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { IClientOptions } from './client'
import type { Packet } from 'mqtt-packet'
import type internal from 'stream'
import type MqttClient from './client'
import { Packet } from 'mqtt-packet'
import { Duplex, Writable } from 'readable-stream'
import type { IClientOptions } from './client'

export type DoneCallback = (error?: Error) => void

export type GenericCallback<T> = (error?: Error, result?: T) => void

export type VoidCallback = () => void

export type IStream = Duplex | Writable
export type IStream = internal.Duplex

export type StreamBuilder = (
client: MqttClient,
Expand Down
1 change: 1 addition & 0 deletions src/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export {
IStore,
}
export * from './lib/client'
export * from './lib/shared'
export { ReasonCodes } from './lib/handlers/ack'

0 comments on commit 247e187

Please sign in to comment.