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

Figure out how to make the client .re.mdx extension work. #2

Closed
cpojer opened this issue May 23, 2023 · 3 comments · Fixed by #16
Closed

Figure out how to make the client .re.mdx extension work. #2

cpojer opened this issue May 23, 2023 · 3 comments · Fixed by #16

Comments

@cpojer
Copy link
Collaborator

cpojer commented May 23, 2023

This should work using TypeScript reference types to declare module "*.re.mdx" but somehow it doesn't get picked up in the example project.

@karlhorky
Copy link
Contributor

karlhorky commented Feb 11, 2024

This sounds interesting for my multi-slide deck implementation 🤔

But I'm not sure I'm understanding completely. What does adding types for the .re.mdx files enable? Are you somehow running TS type checking on your MDX files? Or is it something like the IntelliSense enabled by mdx-analyzer / the MDX VS Code extension?

It looks like this is the workaround for now, to have a separate slides.re.mdx.d.ts file. But if possible I'd like to avoid this from my multi-slide deck setup:

import type {
ComponentList,
ReMDXSlide,
Themes as ThemesType,
} from '@nkzw/remdx';
declare let slides: ReadonlyArray<ReMDXSlide>;
export let Components: ComponentList | undefined;
export let Themes: ThemesType | undefined;
export default slides;

@cpojer
Copy link
Collaborator Author

cpojer commented Feb 12, 2024

The point of these files is so that when you import a .re.mdx file it will be typed correctly by TypeScript so that it can be passed to the render function of ReMDX or transformed in other ways in a type safe way.

Normally it's possible to extend the extensions that TypeScript is aware of by providing these types from within the remdx package, similar to Vite's client types: https://vitejs.dev/guide/features#client-types

I tried various solutions but for some reason I could never figure out a way to just make it work and I ran out of time. As a "hack" I opted to put the .d.ts files into the template, so right now you'd need one of these for each slide deck file. It's not great, and I know it can be solved, but I just didn't get to it. Feel free to send a PR!

@karlhorky
Copy link
Contributor

karlhorky commented Feb 12, 2024

Alright, got a first incomplete (but working) version here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants