Skip to content

Problems using it with TypeScript #2

@kristianmandrup

Description

@kristianmandrup
fastify.ready(err => {
  if (err) throw err

  fastify.ws
    .on('connection', socket => {
      socket.on('message', msg => socket.send(msg)) // Creates an echo server
    })
})

Errors

[ts] Argument of type '(err: any) => void' is not assignable to parameter of type '() => void'.
(parameter) err: any

[ts] Property 'ws' does not exist on type 'FastifyInstance<{}, {}, {}>'.

Had to tweak it to the following to make it compile

fastify.ready(() => {
  fastify['ws']
    .on('connection', socket => {
      socket.on('message', msg => socket.send(msg)) // Creates an echo server
    })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions