isomorphic-ws icon indicating copy to clipboard operation
isomorphic-ws copied to clipboard

Export ClientOptions from 'ws'

Open paralin opened this issue 2 years ago • 10 comments

The ClientOptions are not currently accessible in TypeScript.

paralin avatar Jun 22 '22 21:06 paralin

It seems like a problem with: https://github.com/heineiuo/isomorphic-ws/blob/e7d264a562b5c9ad4a939a789c7ba43968f1ac38/index.d.ts#L8

It should be https://github.com/heineiuo/isomorphic-ws/blob/551ed56ad43e3a4b945a74eb4294557877a1c6da/index.d.ts#L8

@paralin Which version of isomorphic-ws did you used?

heineiuo avatar Jun 23 '22 01:06 heineiuo

@heineiuo currently using 4.0.1 in https://github.com/aperturerobotics/starpc -

I tried importing as import { ClientOptions } from 'isomorphic-ws' since the same works with 'ws' - but of course, that's not exported currently.

paralin avatar Jun 23 '22 03:06 paralin

@paralin I didn't get errors with 4.0.1: Screen Shot 2022-06-23 at 13 22 38

https://codesandbox.io/s/nervous-fire-9hnffn?file=/src/App.tsx

heineiuo avatar Jun 23 '22 05:06 heineiuo

Since you are installing ws anyway, you can use the following code:

import { ClientOptions } from 'ws'

JoCat avatar Jun 23 '22 18:06 JoCat

@heineiuo

image

I guess it's expected now to use export = WebSocket instead of export default WebSocket ?

paralin avatar Jun 24 '22 02:06 paralin

@heineiuo

image

I guess it's expected now to use export = WebSocket instead of export default WebSocket ?

Yes. I'm going to revert the commit which did not published actually.

heineiuo avatar Jun 24 '22 02:06 heineiuo

Isn't it necessary to add more lines like..

import type { ClientOptions } from 'ws'

export { ClientOptions }
export default WebSocket

paralin avatar Jun 24 '22 05:06 paralin

Isn't it necessary to add more lines like..

import type { ClientOptions } from 'ws'

export { ClientOptions }
export default WebSocket

No, it's unnecessary because @types/ws did export = WebSocket;

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/ea4d4e50e11788ef0a8094d7de564ad2f01dfedd/types/ws/index.d.ts#L377

heineiuo avatar Jun 27 '22 10:06 heineiuo

@JoCat @heineiuo I guess there's some confusion here on what I'm asking...

If I try to do this, it doesn't work:

import { ClientOptions } from 'isomorphic-ws'

Is there something that I'm doing wrong here?

paralin avatar Jun 27 '22 21:06 paralin

@JoCat @heineiuo I guess there's some confusion here on what I'm asking...

If I try to do this, it doesn't work:


import { ClientOptions } from 'isomorphic-ws'

Is there something that I'm doing wrong here?

Could you provide a minimal project or a codesandbox link (just like I submitted above)?

heineiuo avatar Jun 28 '22 13:06 heineiuo