refactor: reuse upstream types instead of redeclaring them locally

Import QuartzComponentConstructor and GlobalConfiguration from
@quartz-community/types rather than redeclaring them. Simplify
RecentNotesPluginData to an intersection with Record<string, unknown>
since the redundant fields (slug, filePath, dates, frontmatter) are
already declared on QuartzPluginData.

The plugin genuinely narrows GlobalConfiguration (it assumes locale
and defaultDateType are resolved), so a ResolvedGlobalConfiguration
type alias is kept for that assertion. It is a type intersection
(not an interface extension) to avoid the DTS emission issue that
affected PageList.tsx historically.
This commit is contained in:
saberzero1 2026-04-16 15:22:53 +02:00
parent 9bafc8cacf
commit 29815e206b
No known key found for this signature in database
4 changed files with 11 additions and 34 deletions

File diff suppressed because one or more lines are too long

12
dist/index.d.ts vendored
View file

@ -1,17 +1,7 @@
import { QuartzPluginData, SortFn, QuartzComponent } from '@quartz-community/types';
export { QuartzComponent, QuartzComponentProps, StringResource } from '@quartz-community/types';
type RecentNotesPluginData = QuartzPluginData & {
slug?: string;
filePath?: string;
dates?: Record<string, Date>;
frontmatter?: {
title?: string;
tags?: string[];
[key: string]: unknown;
};
[key: string]: unknown;
};
type RecentNotesPluginData = QuartzPluginData & Record<string, unknown>;
interface RecentNotesOptions {
title?: string;
limit: number;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,7 @@
import type {
GlobalConfiguration,
QuartzComponent,
QuartzComponentConstructor,
QuartzComponentProps,
QuartzPluginData,
SortFn,
@ -12,27 +14,12 @@ import { i18n } from "../i18n";
import { resolveRelative } from "../util/path";
import style from "./styles/recentNotes.scss";
type QuartzComponentConstructor<Options extends object | undefined = undefined> = (
opts: Options,
) => QuartzComponent;
type RecentNotesPluginData = QuartzPluginData & Record<string, unknown>;
type RecentNotesPluginData = QuartzPluginData & {
slug?: string;
filePath?: string;
dates?: Record<string, Date>;
frontmatter?: {
title?: string;
tags?: string[];
[key: string]: unknown;
};
[key: string]: unknown;
};
interface GlobalConfiguration {
type ResolvedGlobalConfiguration = GlobalConfiguration & {
locale: string;
defaultDateType: ValidDateType;
[key: string]: unknown;
}
};
export interface RecentNotesOptions {
title?: string;
@ -55,7 +42,7 @@ export function filterListedPages<T>(pages: T[]): T[] {
return pages.filter((p) => (p as { unlisted?: unknown }).unlisted !== true);
}
const byDateAndAlphabeticalWithConfig = (cfg: GlobalConfiguration): SortFn => {
const byDateAndAlphabeticalWithConfig = (cfg: ResolvedGlobalConfiguration): SortFn => {
const sortFn = byDateAndAlphabetical();
return (f1, f2) =>
sortFn(
@ -64,7 +51,7 @@ const byDateAndAlphabeticalWithConfig = (cfg: GlobalConfiguration): SortFn => {
);
};
const defaultOptions = (cfg: GlobalConfiguration): RecentNotesOptions => ({
const defaultOptions = (cfg: ResolvedGlobalConfiguration): RecentNotesOptions => ({
limit: 3,
linkToMore: false,
showTags: true,
@ -79,7 +66,7 @@ export default ((userOpts?: Partial<RecentNotesOptions>) => {
displayClass,
cfg,
}: QuartzComponentProps & { displayClass?: string }) => {
const globalCfg = cfg as unknown as GlobalConfiguration;
const globalCfg = cfg as ResolvedGlobalConfiguration;
const opts = { ...defaultOptions(globalCfg), ...userOpts };
const pages = filterListedPages(allFiles as RecentNotesPluginData[])
.filter(opts.filter)