versatica / mediasoup-client

mediasoup client side JavaScript library
https://mediasoup.org
ISC License
591 stars 237 forks source link

Make types.ts export only types and not classes #273

Closed ibc closed 1 year ago

ibc commented 1 year ago

As @satoren told in https://github.com/versatica/mediasoup-client/pull/272#issuecomment-1619340353:

Also, it should be noted that import * as mediasoupClientTypes from 'mediasoup-client/lib/types'; imports the actual class, since types.ts exports the actual class, not just the type, for almost all classes. Therefore, there is currently little advantage to importing mediasoup-client/lib/types directly. I think types.ts should be changed to export only types.

NOTE: This was done and later reverted here https://github.com/versatica/mediasoup/commit/760f203dfe19aabe2e46684d8c7814e3cee6dd30 because it requires typescript >= 5 in the apps that import mediasoup-client. We'll do this again once we can assume that all users use typescript >= 5.

ibc commented 1 year ago

I'm reverting changes and reopening this ticket. Explained in the commit: https://github.com/versatica/mediasoup/commit/760f203dfe19aabe2e46684d8c7814e3cee6dd30

Will do it again once we can assume that people uses typescript >= 5 in their apps.

ibc commented 1 year ago

Closing. We do want to export real JS classes. Why not? We want to be able to do this:

import { Producer } from 'mediasoup-client/lib/types';

producer instanceof Producer;

This is not possible if we export Producer as a type.