Skip to content

Commit

Permalink
chore: fix type errors (#1303)
Browse files Browse the repository at this point in the history
* fix type errors

* bring back unkown option

* Apply suggestions from code review

Co-authored-by: Chris Swithinbank <[email protected]>

* add jsx: preserve

* Add changeset

---------

Co-authored-by: Chris Swithinbank <[email protected]>
  • Loading branch information
lilnasy and delucis authored Jan 4, 2024
1 parent ba99daa commit 3eefd21
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-horses-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/starlight": patch
---

chore: fix type errors in Starlight internals
2 changes: 1 addition & 1 deletion docs-i18n-tracker/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const translationStatusBuilder = new TranslationStatusBuilder({
htmlOutputFilePath: './dist/index.html',
sourceLanguage: 'en',
targetLanguages: Object.values(locales)
.reduce((acc, { lang }) => (lang !== 'en' ? [lang, ...acc] : acc), [])
.reduce((acc, { lang }) => (lang !== 'en' ? [lang, ...acc] : acc), new Array<string>())
.sort(),
languageLabels: Object.values(locales)
.filter((loc) => loc.lang !== 'en')
Expand Down
1 change: 1 addition & 0 deletions docs-i18n-tracker/lib/github-get.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import pRetry, { AbortError } from 'p-retry';
export async function githubGet({ url, githubToken = undefined }) {
return await pRetry(
async () => {
/** @type {Record<string, string>} */
const headers = {
Accept: 'application/vnd.github.v3+json',
};
Expand Down
5 changes: 3 additions & 2 deletions docs-i18n-tracker/lib/output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function error(message, ...params) {
/**
* Dedents the given markdown and replaces single newlines with spaces,
* while leaving new paragraphs intact.
* @param {[string | TemplateStringsArray, ...any[]]} markdown
*/
export function dedentMd(...markdown) {
return dedent(...markdown).replace(/(\S)\n(?!\n)/g, '$1 ');
Expand All @@ -56,7 +57,7 @@ export function formatCount(count, template) {
const wrapWithCount = (text) => {
// If no count was given, we're outputting a single issue in annotations,
// so omit count and capitalize the first letter of the issue type description
if (count === undefined) return text[0].toUpperCase() + text.slice(1);
if (count === undefined) return text[0]?.toUpperCase() + text.slice(1);

// Otherwise, prefix the issue type description with count
return `${count} ${text}`;
Expand All @@ -65,7 +66,7 @@ export function formatCount(count, template) {
const usePlural = count !== undefined && count !== 1;
const templateParts = template.split('|');
const usedTemplate = templateParts.length === 2 ? templateParts[usePlural ? 1 : 0] : template;
return wrapWithCount(usedTemplate.replace(/\(s\)/g, usePlural ? 's' : ''));
return wrapWithCount(usedTemplate?.replace(/\(s\)/g, usePlural ? 's' : '') ?? '');
}

export default {
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/theme-designer.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import { TabItem, Tabs } from '@astrojs/starlight/components';
import ColorEditor, { Props as EditorProps } from './theme-designer/color-editor.astro';
import Presets, { Props as PresetsProps } from './theme-designer/presets.astro';
import ColorEditor, { type Props as EditorProps } from './theme-designer/color-editor.astro';
import Presets, { type Props as PresetsProps } from './theme-designer/presets.astro';
import Preview from './theme-designer/preview.astro';
interface Props {
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight/__tests__/i18n/translations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test, vi } from 'vitest';
import { describe, expect, test } from 'vitest';
import translations from '../../translations';
import { useTranslations } from '../../utils/translations';

Expand Down
5 changes: 3 additions & 2 deletions packages/starlight/__tests__/remark-rehype/asides.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ describe('translated labels in French', () => {
Some text
:::
`,
{ fileURL: new URL('./_src/content/docs/fr/index.md', import.meta.url) }
);
// @ts-expect-error fileURL is part of MarkdownProcessor's options
{ fileURL: new URL('./_src/content/docs/fr/index.md', import.meta.url) }
);
expect(res.code).includes(`aria-label="${label}"`);
expect(res.code).includes(`</svg>${label}</p>`);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/starlight/utils/createTranslationSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ function buildDictionary(
// Iterate over alternate dictionaries to avoid overwriting preceding values with `undefined`.
for (const dict of dictionaries) {
for (const key in dict) {
const value = dict[key as keyof typeof dict];
if (value) dictionary[key as keyof typeof dict] = value;
const value = dict[key];
if (value) dictionary[key as keyof typeof dictionary] = value;
}
}
return dictionary;
Expand Down
2 changes: 2 additions & 0 deletions packages/starlight/utils/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let userTranslations: Record<string, i18nSchemaOutput> = {};
try {
// Load the user’s i18n collection and ignore the error if it doesn’t exist.
userTranslations = Object.fromEntries(
// @ts-ignore — may be an error in projects without an i18n collection

(await getCollection('i18n')).map(({ id, data }) => [id, data] as const)
);
} catch {}
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwind/__tests__/tailwind.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tailwindcss, { Config } from 'tailwindcss';
import tailwindcss, { type Config } from 'tailwindcss';
import colors from 'tailwindcss/colors';
import postcss from 'postcss';
import { test, expect, describe, vi } from 'vitest';
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "astro/tsconfigs/strictest",
"exclude": ["**/dist/**", "**/__coverage__/**"],
"compilerOptions": {
"jsx": "preserve",
"allowJs": true,
"checkJs": true
}
Expand Down

0 comments on commit 3eefd21

Please sign in to comment.