refactor(theme-classic): completely migrate package to TypeScript#5459
Conversation
|
✔️ [V2] 🔨 Explore the source changes: 288f191 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/612f6c3f7ba3750008995896 😎 Browse the preview: https://deploy-preview-5459--docusaurus-2.netlify.app |
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5459--docusaurus-2.netlify.app/ |
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
cb659b7 to
a39b77e
Compare
|
|
||
| const highlightLinesRangeRegex = /{([\d,-]+)}/; | ||
| const languageTypes = ['js', 'jsBlock', 'jsx', 'python', 'html'] as const; | ||
| const HighlightLinesRangeRegex = /{([\d,-]+)}/; |
There was a problem hiding this comment.
As I understand PascalCased variables should be objects right? (Also noticed this in docusaurus-init where TypeScriptTemplateSuffix is PascalCased)
There was a problem hiding this comment.
I don't have a strong opinion about JS constant namings as long as it's clear enough those are constants. We already have this convention in other places so just made it consistent, but we can also redefine those conventions if needed
…ugin options for retrocompatibility)
slorber
left a comment
There was a problem hiding this comment.
LGTM thanks 👍
Also refactored a bit the versionBanner prop because handling 'none' with Exclude was not very convenient
|
Yeah, I was thinking about using |
Signed-off-by: Josh-Cena <sidachen2003@gmail.com>
|
Slightly off-topic: I prefer removing inferable types wherever possible, and it also seems to be the case for the majority of TS code across the repo, except for |
|
I feel inferable types have their place in a codebase to avoid some useless duplication (cf highlighted languages using |
This is taken care of by the |
|
I don't always agree with that, extra type annotations on intermediate variables can significantly help readability and also help split a complex data processing algo in multiple "steps" in which you can more easily see which step doesn't typecheck (instead of having the full algo not typechecking). I'd only remove types on a case-by-case basis and limit to the trival types inferences only. |
|
A good example where an algo can be seen as a concatenation of 2 steps, where explicit (but unnecessary) types can help figure out which step fails to typecheck: function collectSidebarItemsOfType<
Type extends SidebarItemType,
Item extends SidebarItem & {type: SidebarItemType}
>(type: Type, sidebar: Sidebar): Item[] {
function collectRecursive(item: SidebarItem): Item[] {
const currentItemsCollected: Item[] =
item.type === type ? [item as Item] : [];
const childItemsCollected: Item[] =
item.type === 'category' ? flatten(item.items.map(collectRecursive)) : [];
return [...currentItemsCollected, ...childItemsCollected];
}
return flatten(sidebar.map(collectRecursive));
} |
|
Yeah, this one makes sense 👍 Thanks for the MWE |
…cebook#5459) * Migrate Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Migrate prism as well Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix lock file Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * Fix typing Signed-off-by: Josh-Cena <sidachen2003@gmail.com> * refactor a bit CodeBlock * simplify versionBanner typing => use null instead of "none" (apart plugin options for retrocompatibility) * Remove return signatures Signed-off-by: Josh-Cena <sidachen2003@gmail.com> Co-authored-by: slorber <lorber.sebastien@gmail.com>
Motivation
Although this package is almost all TS, there are a few JS files + untyped dependencies. This PR completes the TS infrastructure, and thus removed the
noImplicitAny: falseoption intsconfig.json.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
CI
Related PRs
Duplicated work with #5442, should merge that first