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

Feature request: TypeScript definition #18

Closed
JunichiSugiura opened this issue Jul 18, 2020 · 15 comments
Closed

Feature request: TypeScript definition #18

JunichiSugiura opened this issue Jul 18, 2020 · 15 comments
Labels
feature-request New feature or request

Comments

@JunichiSugiura
Copy link

Do you have any plans to migrate to TypeScript?

Whether converting source code to TS or writing definition file, I can help on that so let me know 😉

@jescalan
Copy link
Collaborator

Yes I do, vaguely. I'm be open to either as a contribution if you're interested!

@JunichiSugiura
Copy link
Author

Sure, I'm happy to contribute. Let me know how you wanna go about it and I'll start from there.

@jescalan
Copy link
Collaborator

I think the plan would be either to convert the source to TS or write definition files. Whatever you prefer, I am open to either one.

@JunichiSugiura
Copy link
Author

I'll work on this on Saturday.

@JunichiSugiura
Copy link
Author

Hmmm, seems like mdx-js is working on TypeScript support on v2.

We'll have better Options type once v2 is merged and upgrade the dependency accordingly in this repo. I may leave the type as {[key: string]: any} for now.

@jescalan jescalan added the feature-request New feature or request label Jul 26, 2020
@Howard86
Copy link

Hey guys, first of all, thank you all for this package!
I am using this in my own blog, and quickly forked & rewrote one in TS.

However, I have found some issues after the rework, so I consider simply writing types for this module instead.
(I haven't really check @JunichiSugiura 's version from npm yet, so results can vary)

If you are interested, I have published my forked version on npm for testing purposes. This package will be removed within 3 days following npm policy.

TL;DR

Static page build size is huge after my rework

I am not too sure about the reason (if someone can help I will be more than appreciated), but this puts me off and sticks to the original npm package.

TS version

├ ● /blog/[slug]                                               2.02 MB        2.11 MB
├   ├ /blog/2020-10-07
├   └ /blog/2020-10-21

Original with types

├ ● /blog/[slug]                                               2.86 kB        85.9 kB
├   ├ /blog/2020-10-07
├   └ /blog/2020-10-21

After verifying the network in both pages (build && start), next has built the package in the page.
screenshot

Caveats

Somehow as using fs module in TS version, a next.config.js is required with the following to pass build and test

module.exports = {
  webpack: (config, { isServer }) => {
    // Fixes npm packages that depend on `fs` module
    if (!isServer) {
      config.node = {
        fs: "empty",
      };
    }
    return config;
  },
};

Conclusion

Stick to type declaration for me, and possibly supporting mdx-js rework in TS.

I guess it also relates to the way I use this module outside of /page folder. Will test again after refactoring!

@jescalan
Copy link
Collaborator

@Howard86 wow, this is great - thanks for the thorough rundown!

I would guess honestly that this is your reason for the large bundle size, maybe? In theory this shouldn't be an issue, but I don't know how the code transpiles through, and that seems like the only candidate.

Regardless, I will probably take a serious look at rewriting this package in typescript at some point, but until then just having it ship with types I think would solve everyone's problems, and I'd be happy to accept a contribution to those ends.

@Howard86
Copy link

hmmm interesting...
I have found this in TS Handbook and been using this syntax in production. Maybe I should try using export type & export for separation of concerns

@aoberoi
Copy link

aoberoi commented Dec 22, 2020

👋 If there's anything I can do to help move this issue forward, I'm happy to help.

An update: There are versions of @mdx-js/mdx published under the dist-tag next which already have TypeScript definitions. This should be useful in situations like @JunichiSugiura mentioned above about needing an Options type.

This might not be the right place to ask, but @jescalan, any thoughts or plans regarding support for v2 of @mdx-js/mdx? I haven't taken a close look at the breaking changes, but I'd expect this could necessitate a new major version of this package as well.

Would it be helpful for me to investigate the build size issue that @Howard86 ran into above? That port of this package is no longer available (as noted, deleted after 3 days). Would it be useful for me to contribute an experimental port as a PR to a new branch on this repo?

@jescalan
Copy link
Collaborator

jescalan commented Dec 22, 2020

There's a PR here that adds types - if you could test it on your project(s) and give it a review that would be very helpful @aoberoi - I'm planning to ship it today.

I am planning on supporting mdx version 2 as soon as i can after its release. It will be a major release to this package when it is supported.

If anyone feels capable of completing a functional rewrite of this package in typescript, I would welcome this. So far there have been attempts but nobody has been able to get it across the line. I think shipping native typings should solve the problem for most though.

@Ehesp
Copy link

Ehesp commented Dec 23, 2020

@jescalan I started having a play around with the rewrite here: https://github.com/Ehesp/next-mdx-remote

Some points:

My knowledge of the whole MDX ecosystem isn't great, but hopefully this helps.

EDIT: Also worth adding, since MDX v2 exposes typings, there is a lot less faffing around with manual types.

@raulfdm
Copy link

raulfdm commented Dec 24, 2020

I just tried v2 but it seems the types are not exported.

It means I cannot import the interfaces in my App and use them. 🤔

@jescalan
Copy link
Collaborator

@raulfdm Did you have a chance to check out the readme? https://github.com/hashicorp/next-mdx-remote#typescript

@raulfdm
Copy link

raulfdm commented Dec 26, 2020

@raulfdm Did you have a chance to check out the readme? https://github.com/hashicorp/next-mdx-remote#typescript

Hey @jescalan. I hadn't, I'm sorry.

I had read the update from dependabot and thought it would have a default export via index.js, wrong assumption but thank you for the message.

@jescalan
Copy link
Collaborator

jescalan commented Jan 4, 2021

Closing as we now ship types!

@jescalan jescalan closed this as completed Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants