Skip to content

Type definitions#48

Merged
wooorm merged 19 commits into
remarkjs:mainfrom
uetchy:types
Aug 22, 2020
Merged

Type definitions#48
wooorm merged 19 commits into
remarkjs:mainfrom
uetchy:types

Conversation

@uetchy
Copy link
Copy Markdown
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
Copy Markdown
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)

Comment thread package.json Outdated
Comment thread packages/rehype-mathjax/types/index.d.ts
Comment thread packages/remark-math/package.json Outdated
"dependencies": {},
"devDependencies": {},
"peerDependencies": {
"unified": "^9.0.0"
Copy link
Copy Markdown
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
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. I'll move it to dependencies.

Copy link
Copy Markdown
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).

Comment thread packages/rehype-katex/package.json Outdated
@uetchy
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread packages/rehype-mathjax/chtml.d.ts
Comment thread packages/rehype-mathjax/browser.d.ts Outdated
Comment thread packages/rehype-mathjax/index.d.ts Outdated
@ChristianMurphy
Copy link
Copy Markdown
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
Copy Markdown
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!

Comment thread package.json Outdated
Comment thread packages/rehype-mathjax/index.d.ts Outdated
Comment thread packages/rehype-mathjax/package.json Outdated
Comment thread packages/remark-html-katex/types/index.d.ts Outdated
Comment thread packages/remark-math/package.json Outdated
"dependencies": {},
"devDependencies": {},
"peerDependencies": {
"unified": "^9.0.0"
Copy link
Copy Markdown
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
Copy Markdown
Contributor

pd4d10 commented Aug 18, 2020

Any news?

@ChristianMurphy ChristianMurphy requested a review from a team August 18, 2020 14:28
Copy link
Copy Markdown
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?

Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread package.json Outdated
Co-authored-by: Titus <tituswormer@gmail.com>
Copy link
Copy Markdown
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
Copy Markdown
Member

wooorm commented Aug 22, 2020

Thanks @uetchy, released!!! ✨

zimya pushed a commit to zimya/remark-math that referenced this pull request Jan 13, 2026
Closes remarkjsGH-48.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
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