Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Markdown to TypeScript #3618

Merged
merged 8 commits into from Nov 6, 2018
Merged

Migrate Markdown to TypeScript #3618

merged 8 commits into from Nov 6, 2018

Conversation

captainsafia
Copy link
Member

Closes #3572.

I left some comments in-line about the code.

@@ -23,7 +22,7 @@ const MarkdownRender = (props: ReactMarkdown.ReactMarkdownProps) => {
...props.renderers,
math,
inlineMath
}
} as any
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this any here to get around some type errors that were being thrown up in the ReactMarkdown component. As it turns out, the keys in the renderers object can only be one of the 16 or so node types defined in ReactMarkdown.NodeType. math and inlineMath are not in that set so it throws an error. I trued to expand the declaration of the react-markdown module but had trouble getting it working. I decided to just force it into an any type and call it a day here. Open to any advice on how we can work around this.

export function blockPlugin(opts: Object) {
function blockTokenizer(eat, value, silent) {
export function blockPlugin(this: any, opts: Object) {
function blockTokenizer(eat: any, value: string, silent: boolean) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know how to type eat here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not sure either, this was borrowed and refactored code. @tlyon3

@@ -10,8 +9,8 @@ const MIN_FENCE_COUNT = 2;
const CODE_INDENT_COUNT = 4;

// eslint-disable-next-line no-unused-vars
export function blockPlugin(opts: Object) {
function blockTokenizer(eat, value, silent) {
export function blockPlugin(this: any, opts: Object) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the type on this here to get around an implicit any that it was throwing inside the function.

@@ -216,7 +215,7 @@ export function blockPlugin(opts: Object) {
// Stringify for math block
if (Compiler != null) {
const visitors = Compiler.prototype.visitors;
visitors.math = function(node) {
visitors.math = function(node: any) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again, not sure what type node should be here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok for now. We can have a de-any party someday.

@@ -0,0 +1,3 @@
declare module "trim-trailing-lines" {
export default function trim(value: string): string;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added type definitions for the trim-trailing-lines library since there were none.

Copy link
Member

@rgbkrk rgbkrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookin' pretty good here.

<MathJax.Node>{props.value}</MathJax.Node>
);

const inlineMath = (props: { value: string }) => (
const inlineMath = (props: { value: string }): React.ReactNode => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seem to recall from an earlier review that we don't have to declare the React.ReactNode return type here. Perhaps that was only for render() and not for functional components.

export function blockPlugin(opts: Object) {
function blockTokenizer(eat, value, silent) {
export function blockPlugin(this: any, opts: Object) {
function blockTokenizer(eat: any, value: string, silent: boolean) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not sure either, this was borrowed and refactored code. @tlyon3

@@ -216,7 +215,7 @@ export function blockPlugin(opts: Object) {
// Stringify for math block
if (Compiler != null) {
const visitors = Compiler.prototype.visitors;
visitors.math = function(node) {
visitors.math = function(node: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok for now. We can have a de-any party someday.

@rgbkrk rgbkrk merged commit 9b8dfe7 into master Nov 6, 2018
@rgbkrk rgbkrk deleted the safia/nov/markdown-ts branch November 6, 2018 02:53
@lock lock bot added the outdated workflow: issue should stay closed label Feb 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated workflow: issue should stay closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants