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

fix: fix more types #2893

Merged
merged 14 commits into from
Aug 19, 2023
Merged

fix: fix more types #2893

merged 14 commits into from
Aug 19, 2023

Conversation

UziTech
Copy link
Member

@UziTech UziTech commented Jul 30, 2023

Description

Make types more strict

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel
Copy link

vercel bot commented Jul 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marked-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 19, 2023 10:53pm

src/Tokenizer.ts Outdated Show resolved Hide resolved
src/Instance.ts Outdated Show resolved Hide resolved
src/Instance.ts Outdated Show resolved Hide resolved
src/Instance.ts Outdated Show resolved Hide resolved
const l = tokens.length;
for (i = 0; i < l; i++) {
token = tokens[i];
for (let i = 0; i < tokens.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any perf difference between storing tokens.length in a variable vs checking in here each time? I suspect we won't see much of a different if the length is small but it might add up for large arrays.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no performance benefit from storing the variable first. https://stackoverflow.com/a/17995000/806777

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Thanks! 🥇

@UziTech UziTech merged commit a990c54 into markedjs:master Aug 19, 2023
10 checks passed
@UziTech UziTech deleted the fix-types branch August 19, 2023 22:55
github-actions bot pushed a commit that referenced this pull request Aug 19, 2023
## [7.0.4](v7.0.3...v7.0.4) (2023-08-19)

### Bug Fixes

* fix more types ([#2893](#2893)) ([a990c54](a990c54))
* ignore async: false when async: true is set by an extension ([#2920](#2920)) ([b6ee877](b6ee877))
startInline: Array<(this: TokenizerThis, src: string) => number | void>
})
| undefined | null;
walkTokens?: null | ((token: Token) => void | (unknown | Promise<void>)[]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks downstream compilation because (unknown | Promise<void>)[] gets collapsed to unknown[] jupyterlab/jupyterlab#15020 see https://stackoverflow.com/questions/61685819/typescript-does-not-recognize-a-union-of-type-unknown-and-type-promiseunknown

Should we adapt the type donwstream, or do you consider it a bug?

Copy link
Member

Choose a reason for hiding this comment

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

@UziTech Perhaps this should be (void | Promise<void>)[] instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya I think (void | Promise<void>)[] should work

Copy link
Member Author

Choose a reason for hiding this comment

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

The only time we care about the return value is if async is true. Than we await the return value. I think the problem was that we can't await void in typescript but it is perfectly fine in JavaScript.

Copy link
Member

Choose a reason for hiding this comment

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

The only time we care about the return value is if async is true.

Maybe we need different types when async: true if we want it to be more precise

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be fixed by #2955

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.

4 participants