Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

In TS, emit import react when a react component is exported. #343

Merged
merged 2 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
10 changes: 5 additions & 5 deletions src/EmitJs.re
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1106,9 +1109,7 @@ let getAnnotatedTypedDeclarations = (~annotatedSet, typeDeclarations) =>
};
})
|> List.filter(
(
{exportFromTypeDeclaration: {annotation}}: CodeItem.typeDeclaration,
) =>
({exportFromTypeDeclaration: {annotation}}: CodeItem.typeDeclaration) =>
annotation != NoGenType
);

Expand Down Expand Up @@ -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)
Expand Down