-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
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 <[email protected]>
Signed-off-by: Josh-Cena <[email protected]>
Signed-off-by: Josh-Cena <[email protected]>
Signed-off-by: Josh-Cena <[email protected]>
Signed-off-by: Josh-Cena <[email protected]>
cb659b7
to
a39b77e
Compare
@@ -18,52 +18,63 @@ import styles from './styles.module.css'; | |||
|
|||
import {useThemeConfig, parseCodeBlockTitle} from '@docusaurus/theme-common'; | |||
|
|||
const highlightLinesRangeRegex = /{([\d,-]+)}/; | |||
const languageTypes = ['js', 'jsBlock', 'jsx', 'python', 'html'] as const; | |||
const HighlightLinesRangeRegex = /{([\d,-]+)}/; |
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 understand PascalCased variables should be objects right? (Also noticed this in docusaurus-init
where TypeScriptTemplateSuffix
is PascalCased)
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 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)
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.
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 <[email protected]>
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 |
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: false
option 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