-
-
Notifications
You must be signed in to change notification settings - Fork 236
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
Import non-exported parts of the package #321
Comments
It's worth noting that I want to import these classes to pass them as types in my project, as well as using operations such as |
The majority of classes in YouTube.js are exported from root the library, just in a different way than most other libraries. Some might have been missed and aren't currently exported import { ClientType } from 'youtube.js'; Others are exported in objects that you import: Why is it like this?
|
It's great that they are accessible through the root of the library, but it doesn't help when trying to pass the type as a function parameter. Something like: import Video from "youtubei.js/dist/src/parser/classes/Video";
import PlaylistVideo from "youtubei.js/dist/src/parser/classes/PlaylistVideo";
export function parseVideo(video: Video | PlaylistVideo) would be translated to: import { YTNodes } from "youtubei.js";
export function parseVideo(video: YTNodes.Video | YTNodes.PlaylistVideo) which results in the following TypeScript error: Is there something that I'm missing specifically? |
You could do something like this: import { YTNodes } from "youtubei.js";
const { Video, PlaylistVideo } = YTNodes;
export function parseVideo(video: Video | PlaylistVideo) |
@absidue, @KingRainbow44 |
@LuanRT that change only fixes the issue for YTNodes see #321 (comment) for everything else, also tl;dr you'll have to rename a bunch of classes before you can export them, as exporting multiple identically named Channel classes (also others but that's just the example I chose) won't work. |
@absidue I might be missing something but I tested using those classes as types and it works as expected. If you are sure that's the case, could you provide some examples? Here's the TypeScript code I used to test this: import { Innertube, YT, YTKids } from 'youtubei.js';
export function test1(a: YT.Channel, b: YTKids.Channel) {}
export function test2(a: YT.Channel | YTKids.Channel) {} |
If it works that's great, although it should definitely be documented that the types in YouTube.js are exported that way, instead of them all being directly exported. @KingRainbow44 had to open an issue asking how to import classes and I only figured it out from digging through the source code and happening to have been involved in the refactoring pull request. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Question
I'm trying to import classes from the package. As far as I'm concerned, you can only import them with the absolute path to the class. As of
v3.0.0
, and the change to ESModule, you can no longer import classes from the path.Is it possible to import such classes?
An example imported classes: (and one interface)
Checklist
The text was updated successfully, but these errors were encountered: