iamacup / react-native-markdown-display

React Native 100% compatible CommonMark renderer
MIT License
564 stars 166 forks source link

Type for MarkdownStatic's component props is missing `children` #196

Closed jefflewis closed 8 months ago

jefflewis commented 1 year ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch react-native-markdown-display@7.0.0-alpha.2 for the project I'm working on.

The types for this project do not currently have Children.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-markdown-display/src/index.d.ts b/node_modules/react-native-markdown-display/src/index.d.ts
index f0daf4a..9b11a0c 100644
--- a/node_modules/react-native-markdown-display/src/index.d.ts
+++ b/node_modules/react-native-markdown-display/src/index.d.ts
@@ -1,7 +1,7 @@
 // tslint:disable:max-classes-per-file
 import MarkdownIt from 'markdown-it';
 import Token from 'markdown-it/lib/token';
-import {ComponentType, ReactNode} from 'react';
+import {ComponentType, PropsWithChildren , ReactNode} from 'react';
 import {StyleSheet, View} from 'react-native';

 export function getUniqueID(): string;
@@ -91,7 +91,7 @@ export interface MarkdownProps {
   onLinkPress?: (url: string) => boolean;
 }

-type MarkdownStatic = ComponentType<MarkdownProps>;
+type MarkdownStatic = ComponentType<PropsWithChildren<MarkdownProps>>;
 export const Markdown: MarkdownStatic;
 export type Markdown = MarkdownStatic;
 export {MarkdownIt};

This issue body was partially generated by patch-package.

dendenmuniz commented 11 months ago

Sorry, but how can I use this fix?

Balake commented 10 months ago

@dendenmuniz If you don't want to wait for a release, you can do this:

import React, { ComponentType, PropsWithChildren } from 'react';
import _Markdown, { MarkdownProps } from 'react-native-markdown-display';

type MarkdownWithChildrenT = ComponentType<PropsWithChildren<MarkdownProps>>;
const Markdown = _Markdown as MarkdownWithChildrenT;

export const SomeComponent: React.FunctionComponent = () => {
    const md = '';
    return (
        <Markdown>{md}</Markdown>
    );
};
LeonAvancini commented 8 months ago

@dendenmuniz You should go directly to node modules where you have the library installed, then change the necessary code, in this case are only two lines:

import {ComponentType, PropsWithChildren , ReactNode} from 'react'; type MarkdownStatic = ComponentType<PropsWithChildren<MarkdownProps>>;

After you did the necessary changes play with the code and check if everything is working as you expected.

If everything is working well you should create the patch, to do that I recommend you read the documentation, it's just execute a command npx patch-package <package_name> but before that you need to install patch-package library and configure some scripts on your package.json and that should be all. I hope help with this comment.

MilanBarande commented 8 months ago

I created a pull request for this issue @iamacup