orgapp / orgajs

parse org-mode content into AST
https://orga.js.org
MIT License
614 stars 61 forks source link

Basic TypeScript example using `reorg-rehype` fails to compile #215

Open RangHo opened 11 months ago

RangHo commented 11 months ago

With TypeScript 5.2.2, the simple example below fails to compile due to mismatched type signature.

import { reorg } from '@orgajs/reorg';
import toRehype from '@orgajs/reorg-rehype';
import toHtmlString from 'rehype-stringify';

const pipeline = reorg().use(toRehype).use(toHtmlString);

The error message reads:

src/test.ts:5:51 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(plugin: Plugin<[], Node, Node>, ...settings: [boolean] | []): Processor<any, Node<Data>, Node<Data>, void>', gave the following error.
    Argument of type 'Plugin<[(Options | null | undefined)?], Root, string>' is not assignable to parameter of type 'Plugin<[], Node, Node>'.
  Overload 2 of 3, '(tuple: [Plugin<any[], Node<Data>, Node<Data>>, ...any[]] | [Plugin<any[], Node<Data>, Node<Data>>, boolean]): Processor<...>', gave the following error.
    Argument of type 'Plugin<[(Options | null | undefined)?], Root, string>' is not assignable to parameter of type '[Plugin<any[], Node<Data>, Node<Data>>, ...any[]] | [Plugin<any[], Node<Data>, Node<Data>>, boolean]'.
  Overload 3 of 3, '(presetOrList: Preset | PluggableList): Processor<any, Node<Data>, Node<Data>, void>', gave the following error.
    Argument of type 'Plugin<[(Options | null | undefined)?], Root, string>' is not assignable to parameter of type 'Preset | PluggableList'.

5 export const pipeline = reorg().use(toRehype).use(toHtmlString);
                                                    ~~~~~~~~~~~~

Since the example above works fine under non-typed situations (ESBuild, vanilla JS, etc.), a workaround is possible with // @ts-expect-error directive before the problematic line. I do believe that this is not ideal, though...