Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handshake Headers's Typing should by "any" instead of "object" (v3.1.0) #3770

Closed
Julien-Marcou opened this issue Jan 25, 2021 · 2 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@Julien-Marcou
Copy link

Description

When retrieving the cookie property from the socket's handshake headers, typescript's typing is giving the error Property 'cookie' does not exist on type 'object'.

To reproduce

Socket.IO server version: 3.1.0

Server

import { Server } from 'socket.io';

const io = new Server(3000, {});

io.on('connection', (socket) => {
  // Property 'cookie' does not exist on type 'object'
  console.log(socket.handshake.headers.cookie);

  // Ok
  console.log((socket.handshake.headers as any).cookie);
});

Expected behavior

We should be able to retrieve the cookie property without casting the headers to any.

A better typing could be Record<string, any>.

@Julien-Marcou Julien-Marcou added the bug Something isn't working label Jan 25, 2021
@andrejleitner
Copy link

andrejleitner commented Feb 3, 2021

The same goes for the query attribute (socket.handshake.query) I think.

@darrachequesne
Copy link
Member

This should be fixed by 4f2e9a7 (included in [email protected]).

Thanks for reporting the issue!

@darrachequesne darrachequesne added this to the 3.1.1 milestone Feb 3, 2021
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants