react markdown use in Typescript.
error: TS2604: JSX element type 'Markdown' does not have any construct or call signatures
import * as Markdown from 'react-markdown';
<Markdown source={this.state.content} skipHtml={true} />
tsconfig.json:
{
"compilerOptions": {
"sourceMap": true,
"module": "es6",
"target": "es6",
"lib": [
"dom",
"es7"
],
"jsx": "preserve",
"strict": true,
"noImplicitAny": true,
"moduleResolution": "node",
"baseUrl": "src",
"keyofStringsOnly": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"typeRoots" : [
"node_modules/@types/",
"./typings/markdown.d.ts",
"./typings/typings.d.ts"
]
},
"include": [
"./src/**/*",
"./typings/markdown.d.ts",
"./typings/typings.d.ts"
],
"exclude": [
"node_modules",
"dist"
]
}
markdown.d.ts:
declare function Markdown(props: any): any;
export = Markdown;
Anyone konws how to resolve it?
Thanks very much!
No need markdown.d.ts.
tsconfig.json just add one more line is ok.
"allowSyntheticDefaultImports": true
and change import * as Markdown from 'react-markdown' to import ReactMarkdown from 'react-markdown'
@Duobe's solution works (thanks!), but is there another way to solve the problem without altering tsconfig?
Not really sure how to handle this, happy to accept any pull request addressing this if it can be fixed on "my" end.
Most helpful comment
No need
markdown.d.ts.tsconfig.jsonjust add one more line is ok.and change
import * as Markdown from 'react-markdown'toimport ReactMarkdown from 'react-markdown'