mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
fix(shared): resolve strict ui build typing errors
This commit is contained in:
@@ -20,6 +20,11 @@ interface SharedItemContent {
|
||||
contentPath: string;
|
||||
}
|
||||
|
||||
interface SharedItemContentPayload {
|
||||
content: string;
|
||||
contentPath?: string;
|
||||
}
|
||||
|
||||
function extractErrorFromPayload(payload: unknown, fallbackMessage: string): string {
|
||||
if (
|
||||
typeof payload === 'object' &&
|
||||
@@ -51,6 +56,23 @@ function looksLikeHtml(payloadText: string): boolean {
|
||||
return trimmed.startsWith('<!doctype html') || trimmed.startsWith('<html');
|
||||
}
|
||||
|
||||
function isSharedItemContentPayload(payload: unknown): payload is SharedItemContentPayload {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const candidate = payload as Record<string, unknown>;
|
||||
if (typeof candidate.content !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ('contentPath' in candidate && typeof candidate.contentPath !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async function readJsonOrThrow<T>(response: Response, fallbackMessage: string): Promise<T> {
|
||||
const payloadText = await response.text();
|
||||
const payload = parseJsonPayload(payloadText);
|
||||
@@ -111,7 +133,7 @@ export function useSharedItemContent(
|
||||
throw new Error(extractErrorFromPayload(payload, `Failed to fetch shared ${type} content`));
|
||||
}
|
||||
|
||||
if (payload && typeof payload === 'object' && typeof payload.content === 'string') {
|
||||
if (isSharedItemContentPayload(payload)) {
|
||||
return {
|
||||
content: payload.content,
|
||||
contentPath:
|
||||
|
||||
@@ -399,8 +399,13 @@ interface MarkdownBlockParagraph {
|
||||
text: string;
|
||||
}
|
||||
|
||||
interface MarkdownBlockList {
|
||||
type: 'unordered-list' | 'ordered-list';
|
||||
interface MarkdownBlockUnorderedList {
|
||||
type: 'unordered-list';
|
||||
items: string[];
|
||||
}
|
||||
|
||||
interface MarkdownBlockOrderedList {
|
||||
type: 'ordered-list';
|
||||
items: string[];
|
||||
}
|
||||
|
||||
@@ -413,7 +418,8 @@ interface MarkdownBlockCode {
|
||||
type MarkdownBlock =
|
||||
| MarkdownBlockHeading
|
||||
| MarkdownBlockParagraph
|
||||
| MarkdownBlockList
|
||||
| MarkdownBlockUnorderedList
|
||||
| MarkdownBlockOrderedList
|
||||
| MarkdownBlockCode;
|
||||
|
||||
interface MarkdownFrontmatterEntry {
|
||||
|
||||
Reference in New Issue
Block a user