babel-plugin-import-glob-array icon indicating copy to clipboard operation
babel-plugin-import-glob-array copied to clipboard

Usage with Typescript

Open peduarte opened this issue 5 years ago • 3 comments

Hey Jeff

Loving this package, thanks for building this and next-mdx-enhanced 🙏

I've got a problem when using it with Typescript: image

It seems that its unable to recognise this pattern.

Is this something you've come across before?

Cheers!

peduarte avatar Mar 13 '20 09:03 peduarte

Hey, my stop-gap solution for this at the moment is to add a file @types/mdx.d.ts to my project root with:

interface FrontMatter {
  __resourcePath: string;
  // And so on...
}

declare module "*.mdx" {
  let MDXComponent: (props: any) => JSX.Element;
  export default MDXComponent;
  export const frontMatter: FrontMatter[];
}

Obviously these aren't perfect types, but hey, it gets it working.

maael avatar May 11 '20 20:05 maael

@maael that's smart 👏

My approach was a bit different

In utils/blogPosts.tsx

// @ts-ignore
import { frontMatter } from '../pages/blog/**/*.mdx';
import { FrontMatter } from '../types';

export const blogPosts: FrontMatter[] = frontMatter;

In types/index.tsx

export type FrontMatter = {
  layout?: string;
  title: string;
  publishedAt: string;
  by?: string;
  __resourcePath: string;
};

Consuming

import { blogPosts } from '../utils/blogPosts'

peduarte avatar May 12 '20 08:05 peduarte

Is there any way to push this type of change into this library? If so, I would happily accept a contribution 😀

jescalan avatar Jul 06 '20 18:07 jescalan