Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions packages/core/src/cards/gist.js → packages/core/src/cards/gist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
wrappedTextNode,
wrappedTextStyles,
} from "../common/render.js";
import type { GistData } from "../fetchers/types.js";

import type { GistCardOptions } from "./types.js";

const ICON_SIZE = 16;
const CARD_DEFAULT_WIDTH = 400;
Expand All @@ -24,19 +27,17 @@ const DESCRIPTION_FONT_SIZE = 13;
const DESCRIPTION_LINE_HEIGHT_PX = 16;
const DESCRIPTION_MAX_LINES = 10;

/**
* @typedef {import('./types').GistCardOptions} GistCardOptions Gist card options.
* @typedef {import('../fetchers/types').GistData} GistData Gist data.
*/

/**
* Render gist card.
*
* @param {GistData} gistData Gist data.
* @param {Partial<GistCardOptions>} options Gist card options.
* @returns {string} Gist card.
* @param gistData Gist data.
* @param options Gist card options.
* @returns Gist card.
*/
const renderGistCard = (gistData, options = {}) => {
const renderGistCard = (
gistData: GistData,
options: Partial<GistCardOptions> = {},
): string => {
const { name, nameWithOwner, description, language, starsCount, forksCount } =
gistData;
const {
Expand Down Expand Up @@ -128,9 +129,11 @@ const renderGistCard = (gistData, options = {}) => {
);

const languageName = language || "Unspecified";
// @ts-ignore
// @ts-expect-error Stops TypeScript from raising error.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Suppressing the resulting error-any
const languageColor = languageColors[languageName] || "#858585";

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- Suppressing the resulting error-any
Comment on lines +132 to +136

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FYI the three suppressions have the same root cause: languageColors.json is inferred with literal keys and no index signature, so languageColors[languageName] causes a type error.

Casting languageName to the correct key type would remove the need for all three suppressions.

const svgLanguage = createLanguageNode(languageName, languageColor);

const starAndForkCount = flexLayout({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Card {
}: {
width?: number;
height?: number;
border_radius?: number;
border_radius?: number | undefined;
colors?: CardColors;
customTitle?: string;
defaultTitle?: string;
Expand Down
Loading