diff --git a/Changes.md b/Changes.md index 0f7bec50b..b8b017ad5 100644 --- a/Changes.md +++ b/Changes.md @@ -1,4 +1,6 @@ # master +- With TypeScript back-end, emit import of React when function components are exported. + See https://github.com/cristianoc/genType/issues/342. # 3.8.0 - Alias `Js.Array2.t` to array type. diff --git a/examples/typescript-react-example/src/ExportWithRename.gen.tsx b/examples/typescript-react-example/src/ExportWithRename.gen.tsx index a03816fa6..feb5d152c 100644 --- a/examples/typescript-react-example/src/ExportWithRename.gen.tsx +++ b/examples/typescript-react-example/src/ExportWithRename.gen.tsx @@ -2,6 +2,8 @@ /* eslint-disable import/first */ +import * as React from 'react'; + // tslint:disable-next-line:no-var-requires const ExportWithRenameBS = require('./ExportWithRename.bs'); diff --git a/src/EmitJs.re b/src/EmitJs.re index b505b3f06..ed602a36c 100644 --- a/src/EmitJs.re +++ b/src/EmitJs.re @@ -783,6 +783,9 @@ let rec emitCodeItem = typeVars, resolvedTypeName, }; + if (config.language == TypeScript) { + config.emitImportReact = true; // For doc gen (https://github.com/cristianoc/genType/issues/342) + }; emitExportType( ~emitters, ~config, @@ -1106,9 +1109,7 @@ let getAnnotatedTypedDeclarations = (~annotatedSet, typeDeclarations) => }; }) |> List.filter( - ( - {exportFromTypeDeclaration: {annotation}}: CodeItem.typeDeclaration, - ) => + ({exportFromTypeDeclaration: {annotation}}: CodeItem.typeDeclaration) => annotation != NoGenType ); @@ -1160,8 +1161,7 @@ let propagateAnnotationToSubTypes = retType |> visit; | GroupOfLabeledArgs(fields) | Object(_, fields) - | Record(fields) => - fields |> List.iter(({type_}) => type_ |> visit) + | Record(fields) => fields |> List.iter(({type_}) => type_ |> visit) | Option(t) | Null(t) | Nullable(t)