Skip to content

chore(typescript): add definitions#96

Merged
remarkablemark merged 3 commits intoremarkablemark:masterfrom
nikolay-borzov:typescript-definitions
Mar 18, 2019
Merged

chore(typescript): add definitions#96
remarkablemark merged 3 commits intoremarkablemark:masterfrom
nikolay-borzov:typescript-definitions

Conversation

@nikolay-borzov
Copy link
Copy Markdown
Contributor

@nikolay-borzov nikolay-borzov commented Mar 17, 2019

  • Make build script work on Windows

What is the motivation for this pull request?

Add TypeScript definitions

Resolves #95

- Make `build` script work on Windows
@coveralls
Copy link
Copy Markdown

coveralls commented Mar 17, 2019

Coverage Status

Coverage remained the same at 99.286% when pulling 38e6bba on nikolay-borzov:typescript-definitions into 3722662 on remarkablemark:master.

"coveralls": "cat coverage/lcov.info | coveralls",
"lint": "eslint --ignore-path .gitignore .",
"lint:fix": "npm run lint -- --fix",
"dtslint": "dtslint types",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we also run dtslint in CI and precommit hook?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure it's needed. But I could include it

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yep, I think including would be useful if the library ever was changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I cannot add dtslint as pre-commit hook. It has no support for passing files. It only accepts a folder

"types/*.*": "npm run dtslint"

Causes an error

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

No problem. Running it in CI is enough, thanks for trying!

parse('<a href="#">Heading</a>', {
replace: node => {
if (node.attribs && node.attribs.id === 'header') {
return {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is this return unnecessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have no idea. I took this from dom-to-react.js

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I ask because since this returns only when there's an element with id of header, this if-check will get skipped entirely

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This code isn't actually called. It serves only as type checking sample

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wonder what is type of the returned object though. I haven't figured out it from the source code

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You're right in that the return type is any. I could technically restrict it but I decided to keep it flexible (I'm checking the return value with React.isValidElement()

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "esnext",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Would it be useful to keep the module and lib options as:

{
  "module": "commonjs",
  "lib": ["es2015"]
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok. But I don't think it matters - tsconfig is only needed for linting types

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Gotcha, I'm ok with leaving it as is then

"strictNullChecks": true,
"strictFunctionTypes": true,
"noEmit": true,
"jsx": "react",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nit: technically this option is unnecessary since the library does not use JSX

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's needed for test.tsx since it contains JSX

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good point, thanks for letting me know!

Copy link
Copy Markdown
Owner

@remarkablemark remarkablemark left a comment

Choose a reason for hiding this comment

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

Looks good @nikolay-borzov!

@remarkablemark remarkablemark merged commit 68b403d into remarkablemark:master Mar 18, 2019
@remarkablemark
Copy link
Copy Markdown
Owner

I'll make a release later tonight, thanks once again for making the pull request @nikolay-borzov

d-lazarev pushed a commit to d-lazarev/html-react-parser that referenced this pull request Apr 5, 2019
…efinitions

chore(typescript): add definitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants