Skip to content

Commit

Permalink
Add .re.mdx type declaration files (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky authored Feb 19, 2024
1 parent 2849d4b commit 586dfcf
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/create-remdx/template/remdx-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@nkzw/remdx/client.d.ts" />
2 changes: 1 addition & 1 deletion packages/create-remdx/template/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"target": "es2022"
},
"exclude": ["dist/", "node_modules"],
"include": ["**/*.ts", "**/*.tsx"]
"include": ["remdx-env.d.ts", "**/*.ts", "**/*.tsx"]
}
8 changes: 3 additions & 5 deletions packages/remdx/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { MDXComponents, ReMDXSlide, Themes } from './types';

declare module '*.re.mdx' {
let slides: ReadonlyArray<ReMDXSlide>;
let slides: ReadonlyArray<import('./types.jsx').ReMDXSlide>;

export let Components: MDXComponents | undefined;
export let Themes: Themes | undefined;
export let Components: import('./types.jsx').MDXComponents | undefined;
export let Themes: import('./types.jsx').Themes | undefined;
export default slides;
}
7 changes: 1 addition & 6 deletions packages/remdx/src/deck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ import {
useEffect,
} from 'react';
import { SwipeEventData } from 'react-swipeable';
import { SlideTransition } from '../types.tsx';
import useAspectRatioFitting from './hooks/use-aspect-ratio-fitting.tsx';
import useDeckState from './hooks/use-deck-state.tsx';
import useLocationSync from './hooks/use-location-sync.tsx';
import useMousetrap from './hooks/use-mousetrap.tsx';
import { defaultTransition } from './transitions.tsx';

export type SlideTransition = {
enter?: CSSProperties;
from?: CSSProperties;
leave?: CSSProperties;
};

type DeckContextType = {
activeView: {
slideIndex: number;
Expand Down
3 changes: 2 additions & 1 deletion packages/remdx/src/slide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
} from 'react';
import { animated, useSpring } from 'react-spring';
import { useSwipeable } from 'react-swipeable';
import { DeckContext, SlideTransition } from './deck.tsx';
import { SlideTransition } from '../types.tsx';
import { DeckContext } from './deck.tsx';
import { GOTO_FINAL_STEP } from './hooks/use-deck-state.tsx';
import { Transitions } from './transitions.tsx';

Expand Down
2 changes: 1 addition & 1 deletion packages/remdx/src/transitions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SlideTransition } from './deck.tsx';
import { SlideTransition } from '../types.tsx';

export const defaultTransition: SlideTransition = {
enter: {
Expand Down
38 changes: 34 additions & 4 deletions packages/remdx/types.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
import { MDXProvider } from '@mdx-js/react';
import { CSSProperties } from 'react';
import { SlideTransition } from './src/deck.tsx';

type MDXProps =
typeof MDXProvider extends React.FC<infer Props> ? Props : never;
/**
* Configuration for `MDXProvider`.
*/
type MDXProps = {
/**
* Children (optional).
*/
children?: ReactNode | null | undefined;

Check failure on line 10 in packages/remdx/types.tsx

View workflow job for this annotation

GitHub Actions / test (20, check)

Cannot find name 'ReactNode'.
/**
* Additional components to use or a function that creates them (optional).
*/
components?: Readonly<MDXComponents> | MergeComponents | null | undefined;

Check failure on line 14 in packages/remdx/types.tsx

View workflow job for this annotation

GitHub Actions / test (20, check)

'components' is referenced directly or indirectly in its own type annotation.

Check failure on line 14 in packages/remdx/types.tsx

View workflow job for this annotation

GitHub Actions / test (20, check)

Cannot find name 'MergeComponents'. Did you mean 'MDXComponents'?
/**
* Turn off outer component context (default: `false`).
*/
disableParentContext?: boolean | null | undefined;
};

/**
* Provider for MDX context.
*
* @param {Readonly<MDXProps>} properties
* Properties.
* @returns {JSX.Element}
* Element.
* @satisfies {Component}
*/
function MDXProvider(properties: Readonly<MDXProps>): JSX.Element;

Check failure on line 30 in packages/remdx/types.tsx

View workflow job for this annotation

GitHub Actions / test (20, check)

Function implementation is missing or not immediately following the declaration.

Check failure on line 30 in packages/remdx/types.tsx

View workflow job for this annotation

GitHub Actions / test (20, check)

'MDXProvider' is declared but its value is never read.

export type MDXComponents = MDXProps['components'];

Check failure on line 32 in packages/remdx/types.tsx

View workflow job for this annotation

GitHub Actions / test (20, check)

Type alias 'MDXComponents' circularly references itself.
export type Themes = Record<string, CSSProperties>;

export type SlideTransition = {
enter?: CSSProperties;
from?: CSSProperties;
leave?: CSSProperties;
};

export type ReMDXSlide = {
Component: () => JSX.Element;
data: Record<string, string>;
Expand Down

0 comments on commit 586dfcf

Please sign in to comment.