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

Type definitions #48

Merged
merged 19 commits into from
Aug 22, 2020
Merged

Type definitions #48

merged 19 commits into from
Aug 22, 2020

Conversation

uetchy
Copy link
Contributor

@uetchy uetchy commented Jul 7, 2020

Summary

Fixes #47

Added .d.ts file to each package.

  • remark-math
  • rehype-katex
  • rehype-mathjax
  • remark-html-katex

Discussion

  • Should options have index signature [index: string]: unknown as unified.Settings did?
    • pros: can pass additional options like {position: boolean}
      • another way to deal with it is to explicitly add {position: boolean} to the definition files.
      • or just let users add .use({settings: {position: false}}) to the end of the chain.
    • cons: it will disable key missing errors that help users noticing a typo.

@codecov-commenter

This comment has been minimized.

Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

Thanks @uetchy!
Could you add dtslint type tests? (see remarkjs/remark-rehype#13, or any of the other typing PRs for an example)

package.json Outdated Show resolved Hide resolved
packages/rehype-mathjax/types/index.d.ts Outdated Show resolved Hide resolved
"dependencies": {},
"devDependencies": {},
"peerDependencies": {
"unified": "^9.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

remark/unified generally doesn't use peerDependencies, they can cause trouble.
Generally dependencies or devDependencies are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I'll move it to dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I want to reopen this!

While I think including a package for types is fine (e.g., types/hast, vfile). I don’t think we should do it for unified. I think it should be removed from dependencies, and a note added in the readme that they should be installed (although: plugins don’t make sense w/o unified, so they probably always are installed).

packages/rehype-katex/package.json Outdated Show resolved Hide resolved
@uetchy
Copy link
Contributor Author

uetchy commented Jul 8, 2020

@ChristianMurphy I think all issues you mentioned are resolved now.

@ChristianMurphy ChristianMurphy added ☂️ area/types This affects typings 🦋 type/enhancement This is great to have 🧑 semver/major This is a change labels Jul 8, 2020
Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

Thanks @uetchy !
Would it be possible to add some simple type tests for dtslint?
Something simple like:

unified().use(rehypeKatex);
unified().use(rehypeKatex, {output: 'html'});

// $ExpectError
unified().use(rehypeKatex, {noteARealOption: true});

for each typing

packages/rehype-mathjax/chtml.d.ts Show resolved Hide resolved
packages/rehype-mathjax/browser.d.ts Outdated Show resolved Hide resolved
packages/rehype-mathjax/index.d.ts Outdated Show resolved Hide resolved
@ChristianMurphy
Copy link
Member

Should options have index signature [index: string]: unknown as unified.Settings did?

Generally that is used when settings are generic.
In unified the index signature is a fallback if a package doesn't define it's own settings.
In this case, concrete settings would be preferred, listing out each attribute an its type.

uetchy added a commit to uetchy/remark-math that referenced this pull request Aug 5, 2020
uetchy added a commit to uetchy/remark-math that referenced this pull request Aug 5, 2020
@uetchy
Copy link
Contributor Author

uetchy commented Aug 5, 2020

Would it be possible to add some simple type tests for dtslint?
[omit]
for each typing

@ChristianMurphy Added type test for each package!

package.json Outdated Show resolved Hide resolved
packages/rehype-mathjax/index.d.ts Outdated Show resolved Hide resolved
packages/rehype-mathjax/package.json Outdated Show resolved Hide resolved
packages/remark-html-katex/types/index.d.ts Outdated Show resolved Hide resolved
"dependencies": {},
"devDependencies": {},
"peerDependencies": {
"unified": "^9.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I want to reopen this!

While I think including a package for types is fine (e.g., types/hast, vfile). I don’t think we should do it for unified. I think it should be removed from dependencies, and a note added in the readme that they should be installed (although: plugins don’t make sense w/o unified, so they probably always are installed).

uetchy added a commit to uetchy/remark-math that referenced this pull request Aug 5, 2020
add eslint-disable line to suppress dtslint error
ref: remarkjs#48 (comment)
@pd4d10
Copy link
Contributor

pd4d10 commented Aug 18, 2020

Any news?

@ChristianMurphy ChristianMurphy requested a review from a team August 18, 2020 14:28
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

The changes generally look good, but I’m not a fan of the changes to the ordering of package.json props. Could you revert those?

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

B-E-A-UTIFUL!

@wooorm wooorm merged commit dedc472 into remarkjs:main Aug 22, 2020
@uetchy uetchy deleted the types branch August 22, 2020 17:45
@wooorm
Copy link
Member

wooorm commented Aug 22, 2020

Thanks @uetchy, released!!! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☂️ area/types This affects typings 🧑 semver/major This is a change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

Adding type definitions
5 participants