-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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: Migrate to Typescript #2805
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thank you for this! 💯 This looks like a great start. I have skimmed it, but I will do a more thorough review within the next week. A couple things I see that could change:
|
Most of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to be a breaking change so I think it will take some time to actually get merged in.
Thanks for the review. I hope addressed all your comments now and rebased the changes on master. |
@styfle @calculuschild should we focus on this for v6? and setting deprecated options to false? |
Yeah, sounds good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DreierF if you can rebase this I think we can merge this next so we don't have to keep rebasing.
I'm done with the rebase. I squashed all the rework commits into a single commit to make the rebase less painful. |
src/Instance.ts
Outdated
import { _Renderer } from './Renderer.js'; | ||
import { _Tokenizer } from './Tokenizer.js'; | ||
import { _TextRenderer } from './TextRenderer.js'; | ||
import { _Slugger } from './Slugger.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these prefixed with underscores?
Is there precedence for this convention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned already in the description, I had to rename most internal symbols i.e. Tokenizer
to _Tokenizer
to fix an issue in the generated .d.ts
file, which would otherwise look like
namespace marked {
var Tokenizer: typeof Tokenizer; // Cyclic reference while the second Tokenizer actually did not mean the variable, but the import within the file. Also aliasing the classes on import did not fix the issue.
}
Do you have any better idea on how to overcome this issue?
You should be able to revert that once you get rid of the marked
export and it's extension fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a solution, but I'll second that I don't like the underscores.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good start. We can fix the anys and ignores in future PRs.
@calculuschild do you have any other concerns? I would like to get this merged soon. |
I guess we can merge. I feel like there are probably some more tweaks we can make to clear up the typing syntax in a few places but I think that can be pushed to a later PR. |
Ya I think we should merge this and get a couple other breaking changes in before releasing v6. @DreierF if you can rebase this I can merge it. |
Co-authored-by: Steven <[email protected]>
Great to hear! Rebase is done ✅ |
# [6.0.0](v5.1.2...v6.0.0) (2023-07-31) ### Bug Fixes * Migrate to Typescript ([#2805](#2805)) ([cb54906](cb54906)) ### BREAKING CHANGES * Migrate to Typescript
Description
This PR migrated the codebase to Typescript and automatically generates and publishes a declaration file which fixes #1732.
I tried to keep the actual code changes that change semantics of the code as small as possible. To simplify the publishing I replaced the rollup setup with tsup, which makes bundling the declaration files a lot easier. I started off with the declarations from Definitely Typed pulled them into the actual code as far as it made sense to me. I also copied over the tests from Definitely Typed.
In contrast to the Definitely Typed types the types are no longer part of the marked Namespace i.e.
marked.MarkedOptions
->MarkedOptions
as I did not find a way to preserve both the call signature on the namespace (marked(...)
) in addition to exporting the types within the namespace. As this has no effect on runtime behavior and only requires trivial changes in Typescript code on user side this was the best tradeoff I could think of. Also namespaces are generally no longer recommended in Typescript so this seemed like a good direction anyway.I also had to rename most internal symbols i.e.
Tokenizer
to_Tokenizer
to fix an issue in the generated.d.ts
file, which would otherwise look likeFuture work
Obviously there is a bunch of places that could be more strictly/cleanly typed, but for now I focused on the exposed API as fixing the type errors within the functions will most of the time require code refactorings which would have made the PR un-reviewable.
@UziTech Please have a look and let me know what you think :)
I have pulled out the renaming from *.js to *.ts to a separate commit to make it easier to review.
Contributor
Committer
In most cases, this should be a different person than the contributor.